vue中watch同时监听多个数据的变化

  data(){
    return {
      fromList: {
        custType: "", 
        Organization: "", 
      },
      btnDisabled: true,
    };
  },
  computed: {
    change() {
      const { custType, Organization } = this.fromList; //如果直接写在data里,则直接=this
      return { custType, Organization };
    },
  },
  watch: {
    change: {
      handler(newValue) {
        if (newValue.custType && newValue.Organization) {
          this.btnDisabled = false;  //当custType, Organization 都为true的时候,btnDisabled为false
        }
      },
      deep: true,
      immediate: true,
    },
  },
posted @ 2022-05-30 20:37  粥粥。  阅读(505)  评论(0)    收藏  举报