Vue.js 中使用 $forceUpdate() 强制更新组件
您可以在 Vue.js 中使用 $forceUpdate() 方法来强制更新组件,即使数据没有改变。在这种情况下,watcher 将重新运行,从而更新 this.sizeForm.classifyPid 的值。
修改后的代码如下:
watch: {
pid() {
this.sizeForm.classifyPid = this.pid;
console.log(222, this.sizeForm.classifyPid);
},
},
methods: {
updateClassifyPid() {
this.$forceUpdate();
},
}
您可以在需要更新的地方调用 updateClassifyPid() 方法来强制更新组件。这将重新运行 watcher 并更新 this.sizeForm.classifyPid 的值。
原文地址: https://www.cveoy.top/t/topic/nCQw 著作权归作者所有。请勿转载和采集!