我知道解决方案是像这样更新 Prop 数据:
this.selectedContinent = ""
但我想使用另一种解决方案
在我阅读了一些引用之后,解决方案是:
this.$forceUpdate()
我试过了,还是不行
演示和完整代码如下:
https://jsfiddle.net/Lgxrcc5p/13/
可以点击按钮测试试试
除了更新属性数据,我需要一个解决方案
最佳答案
您必须为您的组件分配一个键。当你想重新渲染一个组件时,你只需更新 key 。 更多信息 here .
<template>
<component-to-re-render :key="componentKey" />
</template>
export default {
data() {
return {
componentKey: 0
}
},
methods: {
forceRerender() {
this.componentKey += 1
}
}
}
关于vue.js - 如何重新加载 vue 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46211297/