有不为 發表於 2025-12-10 16:29:00

如何实现 vxe-tree 树组件拖拽节点后进行二次确认提示

<p>如何实现 vxe-tree 树组件拖拽节点后进行二次确认提示,参数 drag-config.dragStartMethod 可以自定义处理拖拽开始时的拖动,可以自定义是否允许拖拽</p>
<p>官网:https://vxeui.com<br>
github:https://github.com/x-extends/vxe-pc-ui<br>
gitee:https://gitee.com/x-extends/vxe-pc-ui</p>
<p><img src="https://img2024.cnblogs.com/blog/3563285/202512/3563285-20251210162900820-1454588254.gif"></p>
<p>需要提示操作时,通过 drag-config.dragEndMethod 可以自定义处理拖拽结束时的拖动</p>
<pre><code class="language-html">&lt;template&gt;
&lt;div&gt;
    &lt;vxe-tree v-bind="treeOptions"&gt;&lt;/vxe-tree&gt;
&lt;/div&gt;
&lt;/template&gt;

&lt;script setup&gt;
import { reactive } from 'vue'
import { VxeUI } from 'vxe-pc-ui'

const treeOptions = reactive({
transform: true,
drag: true,
dragConfig: {
    isCrossDrag: true,
    isSelfToChildDrag: true,
    showGuidesStatus: true,
    async dragEndMethod () {
      const type = await VxeUI.modal.confirm({
      content: '请是否确认调整顺序?'
      })
      if (type === 'confirm') {
      return true
      }
      VxeUI.modal.message({
      content: '操作已取消',
      status: 'warning'
      })
      return false
    }
},
data: [
    { title: '节点2', id: '2', parentId: null },
    { title: '节点3', id: '3', parentId: null },
    { title: '节点3-1', id: '31', parentId: '3' },
    { title: '节点3-2', id: '32', parentId: '3' },
    { title: '节点3-2-1', id: '321', parentId: '32' },
    { title: '节点3-2-2', id: '322', parentId: '32' },
    { title: '节点3-3', id: '33', parentId: '3' },
    { title: '节点3-3-1', id: '331', parentId: '33' },
    { title: '节点3-3-2', id: '332', parentId: '33' },
    { title: '节点3-3-3', id: '333', parentId: '33' },
    { title: '节点3-4', id: '34', parentId: '3' },
    { title: '节点4', id: '4', parentId: null },
    { title: '节点4-1', id: '41', parentId: '4' },
    { title: '节点4-1-1', id: '411', parentId: '42' },
    { title: '节点4-1-2', id: '412', parentId: '42' },
    { title: '节点4-2', id: '42', parentId: '4' },
    { title: '节点4-3', id: '43', parentId: '4' },
    { title: '节点4-3-1', id: '431', parentId: '43' },
    { title: '节点4-3-2', id: '432', parentId: '43' },
    { title: '节点5', id: '5', parentId: null }
]
})
&lt;/script&gt;
</code></pre>
<p>https://gitee.com/x-extends/vxe-pc-ui</p><br><br>
来源:https://www.cnblogs.com/qaz666/p/19332234
頁: [1]
查看完整版本: 如何实现 vxe-tree 树组件拖拽节点后进行二次确认提示