天爱天
天爱天
  • 发布:2023-01-15 12:58
  • 更新:2023-01-15 12:58
  • 阅读:1163

不修改组件代码,uni-data-picker选择中间节点的方法

分类:uni-app

模板中添加事件

<uni-data-picker :step-searh="true" self-field="_id" parent-field="parent_id" v-model="formData.d_ids" collection="opendb-department" field="_id as value, name as text,parent_id" @nodeclick="nodeclick" @popupclosed="popupclosed"></uni-data-picker>

data()函数的return部分添加个变量

      return {  
        tempPdid:"",

方法中添加上面事件对应的方法

    methods: {  
      nodeclick(e){  
        this.tempPdid = e.value  
      },  
      popupclosed(){  
        this.formData.d_ids = this.tempPdid  // 这个例子是用户修改页,d_ids是uni-id-users表的部门字段  
      },

操作效果:点击任意节点,再点击选框之外,会自动关闭选框,选项即生效。

0 关注 分享

要回复文章请先登录注册