父页面(传totalData):
<govern-transaction-amount ref="governTransactionAmount" :totalData="totalData">
</govern-transaction-amount>
子组件接收:
props: {
totalData: Object,
},
watch: {
totalData: {
immediate: true,
handler(newValue) {
this.newAmount = newValue.newAmount;
this.collectedAmount = newValue.collectedAmount;
}
},
},
tips: 确保首次渲染更新,在监听中设置: immediate: true
immediate: true :表示在watch中首次绑定的时候,是否执行handler,值为true则表示在watch中声明的时候,就立即执行handler方法,值为false,则和一般使用watch一样,在数据发生变化的时候才执行handler。所以当为true时 在created周期里就可以不用在写 已经在watch 中写过的方法了