<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>
出现这个问题就是绑定了对象(需求如此),render函数没有自动更新,数据刷新了,但是视图没有刷新,而this.$set和this.$forceUpdate就是重新render。
解决办法:
1.通过this.$set()解决
changeUnit(item) {
// 向this.$set() 里传入3个参数, 第一个是包裹字段的父级对象, 第二个是目标字段, 第三个是将要赋值给目标字段的数据
this.$set(this.confirmPriceVo.recUnit,'recUnit',item);
}
2.通过this.$forceUpdate()解决
changeUnit() {
this.$forceUpdate();
}