• ElementUI级联选择组件的默认值回显问题


    Element-UI级联选择器Cascader,经过v-model保存选择项的值,数据类型为数组,数组元素为所选不一样级别选项的值。

    html部分:

    <el-cascader v-model="editForm.goods_cat" :options="cateList" :props="props" @change="handleCateChange">
    </el-cascader>

    script部分:

    data() {
        return {
            // 添加商品表单数据
          editForm: {
            goods_name: '',
            goods_price: 0,
            goods_weight: 0,
            goods_number: 0,
            goods_cat: [],
            pics: [],
            attrs: [],
            goods_introduce: ''
          },
          // 级联选择器的数据源
          cateList: []
        }
    }
    ......
    created() {
        // 设置级联选择器数据源
        this.cateList = this.getCateList();
        // 设置级联选择器绑定值
        const tempArray = res.data.goods_cat.split(',');
        // 这里必须从新赋值为空数组,再赋值,不然v-model不能实现默认值回显
        this.editForm.goods_cat = [];
        tempArray.forEach(item => {
          // item - 0是把数据类型转换为数字,以与cateList 数据类型一致,不然不能正确回显默认值
          this.editForm.goods_cat.push(item - 0);
        });
    }

    代码中实现了默认值回显,其中,代码this.editForm.goods_cat = []; 很关键,估计与Vue生命周期及组件解析和二次渲染等有关,或者就是一个bug。

  • 相关阅读:
    详谈 Jquery Ajax 异步处理Json数据.
    基于Jquery+Ajax+Json+高效分页
    JSON资料整理
    站立会议第七天
    站立会议第六天
    站立会议第五天
    站立会议第四天
    用户场景分析
    站立会议第三天
    站立会议第二天
  • 原文地址:https://www.cnblogs.com/windok/p/15600333.html
Copyright © 2020-2023  润新知