vue-treeselect的基本使用以及如何更改id以及label的绑定值

一、最主要的几点就是

1、绑值:value=“form.astdeptId”,主要绑的就是id,通过id找到对应的label回显

2、options是数据源,正常调接口获取就行了

3、append-to-body="true"这个最好加上,可能会遇到下拉的弹窗打不开或者只有一点点高的情况

4、(******) normalizer属性就是把我们自己的后端返的数据格式按树插件需要的格式转换

tenantIdnormalizer(node) {
  if (node.children && !node.children.length) {
    delete node.children
  }
  return {
    id: node.id,
    label: node.name,
    children: node.children
  }
},

5、select点击事件里赋值

6、插槽slot=“option-label” 是下拉框的值

7、插槽slot=“value-label” 是输入框回显的值

文章来源地址https://uudwc.com/A/dbxXx

二、引入

import XTreeselect from ‘@riophae/vue-treeselect'
// 样式
import ‘@riophae/vue-treeselect/dist/vue-treeselect.css'

三、使用

<!--
 * @Description: ------ 文件描述 ------
 * @Creater: snows_l snows_l@163.com
 * @Date: 2023-02-03 16:37:11
 * @LastEditors: snows_l snows_l@163.com
 * @LastEditTime: 2023-02-06 11:05:57
 * @FilePath: /lg-ebt-backend-vue-top2-2/package/module/system/src/views/approvalManage/approvalEdit/Dialog.vue
-->
<template>
  <el-dialog
    title="编辑流程"
    :visible.sync="dialogVisible"
    width="50%"
    :before-close="handleClose"
  >
    <el-form
      ref="personalForm"
      size="small"
      :model="baseInfo"
      :rules="rules"
      label-position="right"
      label-width="120px"
    >
      <el-row class="pd20">
        <el-col :span="18">
          <el-form-item label="审批流程名称:" prop="approvalName">
            <span>{{ baseInfo.approvalName }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="18">
          <el-form-item label="人员选择:" prop="approvalPersnal">
            <x-tree-select
              v-model="baseInfo.approvalPersnal"
              :multiple="true"
              :options="optionss"
              placeholder="请选择人员"
              :normalizer="tenantIdnormalizer"
            >
              <div
                slot="option-label"
                slot-scope="{ node }"
                style="white-space: nowrap; font-size: 14px"
              >
                {{ node.raw.name ? node.raw.name + "-snows" : "" }}
              </div>
              <div slot="value-label" slot-scope="{ node }">
                {{ node.raw.name ? node.raw.name + "-s" : "" }}
              </div>
            </x-tree-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import XTreeSelect from "@riophae/vue-treeselect"
// import the styles
import "@riophae/vue-treeselect/dist/vue-treeselect.css"
export default {
  name: "",
  components: {
    XTreeSelect
  },
  data() {
    return {
      dialogVisible: false,
      baseInfo: {
        approvalName: "",
        approvalPersnal: []
      },
      options: [
        {
          id: 1,
          name: "东南",
          children: [
            {
              id: 2,
              name: "上海",
              children: [
                { id: 3, name: "普陀" },
                { id: 4, name: "黄埔" },
                { id: 5, name: "徐汇" }
              ]
            },
            {
              id: 7,
              name: "江苏",
              children: [
                { id: 8, name: "南京" },
                { id: 9, name: "苏州" },
                { id: 10, name: "无锡" }
              ]
            },
            {
              id: 12,
              name: "浙江",
              children: [
                { id: 13, name: "杭州" },
                { id: 14, name: "宁波" },
                { id: 15, name: "嘉兴" }
              ]
            }
          ]
        },
        {
          id: 17,
          name: "西北",
          children: [
            {
              id: 18,
              name: "陕西",
              children: [
                { id: 19, name: "西安" },
                { id: 20, name: "延安" }
              ]
            },
            {
              id: 21,
              name: "新疆维吾尔族自治区",
              children: [
                { id: 22, name: "乌鲁木齐" },
                { id: 23, name: "克拉玛依" }
              ]
            }
          ]
        }
      ],
      
    }
  },

  created() {},

  methods: {

    tenantIdnormalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    },
  }
}
</script>

<style lang="scss" scoped></style>

原文地址:https://blog.csdn.net/snows_l/article/details/128898578

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年09月26日 15:46
Java-heap dump 文件分析
下一篇 2023年09月26日 15:46