当需要监听对象的某一个属性的时候写法:

data:{
    toEditForm: {
              id: null,
              functionType: null
            }
},
 computed: {
      "toEditFormWfId": function(){
        return this.toEditForm.wfId
      }
    },

    //同步职能分类名称
    watch:{
      "toEditFormWfId": function (val) {
        // var that = this

        const obj = this.workFunctionList.find((item) =>  item.id == val);
        if( obj ){  //此判断非常重要 
          this.toEditForm.functionType = obj.functionType ;
        }
      }
    }

判断重要的原因是: 如果没有此判断 ,当此页面再次刷新的时候,会报“functionType is undefined”的错误。

Logo

前往低代码交流专区

更多推荐