vue this.$forceUpdate() 处理页面刷新问题(v-for循环值刷新等)

**

问题描述:

**
在使用Vue框架开发时,在函数中改变了页面中的某个值,在函数中查看是修改成功了,但在页面中没有及时刷新改变后的值;

解决:

运用 this.$forceUpdate() 强制刷新(因为数据层次太多,render函数没有自动更新,需手动强制刷新。)

代码案例

<Select v-model="carSafeLine.insuranceName" placeholder="请选择" class="mulisel option-h" filterable clearable :disabled="editstatus" @on-change="selectInsurance">
  <Option v-for="item in dataArr" :key="item.code" :value="item.code" :label="item.codename" :disabled="item.disabled"></Option>
</Select>

methods: {
  selectInsurance(){ //刷新车辆保险可选状态
    for(var i=0; i<this.dataArr.length; i++){ 
      var flag = false; //默认没有选中
      var itemI = this.dataArr[i];

      for(var j=0; j<this.form.carInsuranceVOList.length; j++){ //检测选项是否已被选中过
        var itemJ = this.form.carInsuranceVOList[j];
        if(itemI.code == itemJ.insuranceName){
          flag = true;
          break;
        }
      }

      if(flag){
        itemI.disabled = true;
      }else{
        itemI.disabled = false;
      }
    }

    this.$forceUpdate(); //强制刷新,解决页面不会重新渲染的问题
  }
}

后续我会把我的代码贴出来,目前看是转载的:https://blog.csdn.net/xuaner8786/article/details/81217075

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值