vue プロジェクトで計算および監視するアプリケーション

watch: データ変更は複数のデータ変更に影響します

例:複数の売掛金データの変更により、売掛金の合計金額が変更される場合

<div>应收: {
   
   { historyCostTotal.toLocaleString() }}元</div>

    computed: {
      //  应收
      historyCostTotal() {
        let all = 0
        this.historyContractList.forEach(item => {
          all += Number(item.receivableAmount)
          this.list[0].amountPaid = all
        })
        return all
      },
    },

 watch: データ変更は複数のデータ変更に影響します

例: 時間が変更されると、フォームのヘッダー時間も変更されます。

getLabel为子组件的渲染表头的方法————month月份变化
getList为子组件调用接口的方法————params传值变化


watch: {
      params: {
        deep: true,
        handler(newV, oldV) {
          this.params = newV;
          if (newV && this.type == '2' && this.channelFlag == '0') {
            this.getList();
          }
        }
      },
    month: {
      deep: true,
      handler(newV, oldV) {
        this.month = newV;
        if (newV) {
          this.getLabel(this.timeType)
        }
      }
    },
  },

おすすめ

転載: blog.csdn.net/m0_65274248/article/details/128058094
おすすめ