首页 > 其他分享 >vue tree展开自动获取焦点

vue tree展开自动获取焦点

时间:2024-06-12 11:23:17浏览次数:12  
标签:node vue const mc tree bh sys 获取 topItem

 打开弹窗设置默认焦点

html代码

重点: 设置 node-key="id"  ref="table_dedh"

<el-tree :data="dedhtreeData" node-key="id" ref="table_dedh" :props="{ children: 'children', label: 'label'}" @node-click="dedhhandleNodeClick"></el-tree>

js代码

数据渲染时设置id

在数据渲染后设置焦点

// 通过DOM选择器查找节点
const node =table_dedh.value?.$el.querySelector('[data-key="0"]'); 
if (node) {
  node.scrollIntoView();
  node.focus(); // 假设节点是可聚焦的
}

const dedhtreeData = ref([])
const table_dedh = ref()

// 弹窗事件

const getDedhsubmit = (index, row) => {

  //获取展示数据

  //整理数据设置id

  const transformItems = (items,indexs) => {

    return items.map((item,index) => ({

      id: `${indexs}-${index}`,

      label: `${item.sys_mc}【${item.sys_bh}】`,

      params: {

        code: item.sys_bh

      },

      children: item.bh_mc ? transformItems(item.bh_mc) : []

    }));

  };

  const transformedData2 = getPieceWorks.data.map((topItem,indexs) => ({

    id: indexs,

    label: `${topItem.sys_mc}【${topItem.sys_bh}】`,

    params: {

      code: topItem.sys_bh

    },

    children: topItem.bh_mc ? transformItems(topItem.bh_mc,indexs) : []

  }));

  //渲染数据

  dedhtreeData.value = transformedData2;

  nextTick(() => {

    // 手动设置选中节点,如果默认选中不生效,可以使用此方法

    if (table_dedh.value) {

      const tree = table_dedh.value?.$el; // 访问组件实例的 $el

      if (tree) {

        // 通过DOM选择器查找节点

        const node = tree.querySelector('[data-key="0"]');

        if (node) {

          node.scrollIntoView();

          node.focus(); // 假设节点是可聚焦的

        }

      }

    }

  });

}

 

标签:node,vue,const,mc,tree,bh,sys,获取,topItem
From: https://www.cnblogs.com/cmooc/p/18243379

相关文章

  • ThingsBoard前端Vue版本开源啦!!!!
    ThingsVue......
  • C# 获取当前服务器域名
    C#获取当前服务器域名"http://"是协议名"www.test.com"是域名"aaa"是站点名"bbb.aspx"是页面名(文件名)"id=5&name=kelli"是参数//获取完整url(协议名+域名+站点名+文件名+参数)stringurl=Request.Url.ToString();url="http://www.test.com/aaa/b......
  • 搭建vue项目准备-配置git信息
    搭建vue项目准备1、node-v2、npm-v3、git-versionnpm淘宝镜像1、npmconfigsetregistryhttps://registry.npm.tobacco.org/设置淘宝镜像2、npmconfiggetregistry查看镜像地址vscode插件vetureslint安装clinpminstall-g@vue/clivue--versi......
  • Vue 中数组常用方法的使用和示例
    Find查找数组元素Find用来遍历查找数组元素,当找到符合条件的元素时,直接返回。所以Find元素只会返回符合条件的第一个元素//数据types:[{"value":0,"label":"头像素材"},{"value":1,......
  • 基于HTTP传输协议、cJSON库的网络天气获取程序
    基于HTTP传输协议、cJSON库的网络天气获取程序#include<stdio.h>#include<string.h>#include<strings.h>#include<sys/socket.h>#include<netinet/in.h>#include<arpa/inet.h>#include<stdlib.h>#include<errno.h>#include......
  • vue PDF预览——vue-pdf用法
    第一步 引入vue-pdfnpminstall--savevue-pdf第二步 页面中使用<template><div><button@click="open">打开PDF</button><el-dialogtitle="PDf预览":visible.sync="dialogVisible"width="50%":......
  • ExecuteReader 获取数据集的基础使用
    ///<summary>///获取多个结果集///</summary>///<paramname="sql"></param>///<returns></returns>///<exceptioncref="Exception"></exception>publicstaticSqlDataReaderGetReader(strings......
  • Vue3——setup语法糖
    setup概述setup是Vue3中新的配置项,值是一个函数,组件中所用到的数据、方法、计算属性、监视等等,均配置在setup中。setup函数返回的对象中的内容,可直接在模版中使用。setup中不能使用this关键字,this是undefined。setup会在beforeCreate()函数之前调用,领先所有的钩子函数执行的......
  • Vue事件修饰符
    1.vue的事件修饰符有哪些.stop.prevent.self.capture.once.passive 2.使用方法.stop,相当于原生写法中的event.stopPropagation(),用于阻止事件冒泡<template><div@click="father"><[email protected]="son"></button></div>&l......
  • 基于jeecgboot-vue3的Flowable流程--抄送我的功能
    因为这个项目license问题无法开源,更多技术支持与服务请加入我的知识星球。1、抄送我的界面代码如下:<template><divclass="p-2"><!--查询区域--><divclass="jeecg-basic-table-form-container"><a-formref="formRef"@keyup.enter.nati......