描述:

选中后数据不更新,给数据重新添加  this.$set(this.form,"userId",res.data.userId) 依然没有用

 

解决方案

$nextTick
作用:vue中的nextTick()是在下次 DOM 更新循环结束之后执行延迟回调,在修改数据之后使用$nextTick(),则可以在回调中获取更新后的 DOM。

forceUpdate
作用:在Vue官方文档中指出,$forceUpdate具有强制刷新的作用,迫使vue实例重新(rander)渲染虚拟dom,注意它仅仅影响实例本身和插入插槽内容的子组件,而不是所有子组件。

实例

<el-select 
   v-model="form.userId" 
   @change="selectShenPiRenChange"
   placeholder="请选择状态">
   <el-option
      v-for="item in selectShenPiRenList"
      :key="item.id"
      :label="item.userName"
      :value="item.id">
   </el-option>
</el-select>
// 获取 审批人 的name
    selectShenPiRenChange(val){
      this.form.userId=this.selectShenPiRenList.find(
        item=> item.id==val
      ).id;
      this.form.userName=this.selectShenPiRenList.find(
        item=> item.id==val
      ).userName;
      this.$nextTick(() => {
        this.$forceUpdate()
      })
    },

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐