el-tree树形拖拽菜单刷新默认点击第一个、非默认选中vue3

树形拖拽菜单刷新默认点击第一个、非默认选中。

ref="tree"  node-key="id",     setCurrentKey=>选中高亮

    const treeRef = ref(null);
    watch(
      () => tree.data,
      (nVal) => {
        if (nVal) {
          console.log(nVal[0].id);
          $nextTick(() => {
            if (diffType.value == 'add') {
              treeRef.value.setCurrentKey(nVal[nVal.length - 1].id) ;
            } else {
              treeRef.value.setCurrentKey(nVal[0].id) ;
            }
          });
        }
      }
    );
watch(
      () => tree.data,
      (nVal) => {
        if (nVal) {
          $nextTick(() => {
            if (diffType.value == 'add') { //添加到最后一个 默认选中最后一个
              let arr = document.querySelectorAll('.el-tree-node');
              arr[arr.length - 1].click();
            } else {
              document.querySelector('.el-tree-node__content').click();//默认选中第一个
            }
          });
        }
      }
    );

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Vue2中使用Sortable.js实现两个el-table之间的树形结构功能,可以按照以下步骤进行操作: 1. 安装Sortable.js和Vue-Sortable插件: ```bash npm install sortablejs vue-sortable ``` 2. 在Vue组件中引入并使用Vue-Sortable插件: ```vue <template> <div> <el-table :data="treeData1" :row-key="row => row.id" ref="table1" > <!-- 表格列定义 --> </el-table> <el-table :data="treeData2" :row-key="row => row.id" ref="table2" > <!-- 表格列定义 --> </el-table> </div> </template> <script> import Sortable from 'sortablejs'; import { VueSortable } from 'vue-sortable'; export default { components: { VueSortable }, data() { return { treeData1: [ // 表格数据 ], treeData2: [ // 表格数据 ] }; }, mounted() { this.$nextTick(() => { this.makeTablesSortable(); }); }, methods: { makeTablesSortable() { Sortable.create(this.$refs.table1.$el, { group: 'table', animation: 150, onEnd: this.onTableDragend }); Sortable.create(this.$refs.table2.$el, { group: 'table', animation: 150, onEnd: this.onTableDragend }); }, onTableDragend(event) { const sourceTable = event.from === this.$refs.table1.$el ? 'table1' : 'table2'; const targetTable = event.to === this.$refs.table1.$el ? 'table1' : 'table2'; const sourceData = this[sourceTable]; const targetData = this[targetTable]; // 根据event对象中的信息,更新sourceData和targetData的顺序 } } }; </script> ``` 在上面的示例代码中,我们使用Vue-Sortable插件将Sortable.js应用于el-table。通过在mounted钩子函数中调用makeTablesSortable方法,我们创建了两个可的Sortable实例,并将其应用于el-table组件。在onEnd回调函数中,我们可以根据事件的信息来更新sourceData和targetData的顺序,从而实现树形结构的功能。 请注意,上述代码仅提供了一个基本的示例,具体的更新逻辑需要根据你的业务需求来实现。 希望以上信息对你有所帮助!如果有任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值