<el-select
    v-model="confirmPriceVo.recUnit"
    filterable
    allow-create
    default-first-option
    @change='changeUnit'
    placeholder="单位(可选择可自填)">
        <el-option
             v-for="(item, index) in ['', '分钟', '', '']"
            :key="index"
            :label="item"
            :value="item"
            >
        </el-option>
</el-select>

出现这个问题的原因是绑定了对象,数据刷新了但视图没有刷新。

解决办法:

  1. 通过this.$set()解决
changeUnit(item) {
    // 向this.$set() 里传入3个参数, 第一个是包裹字段的父级对象, 第二个是目标字段, 第三个是将要赋值给目标字段的数据
    this.$set(this.confirmPriceVo.recUnit,'recUnit',item);
}
  1. 通过this.$forceUpdate()解决
changeUnit() {
    this.$forceUpdate();
}

更多推荐