只是一个简单的问题。
你能强迫Vue.js重新加载/重新计算所有内容吗?如果有,怎么做?
只是一个简单的问题。
你能强迫Vue.js重新加载/重新计算所有内容吗?如果有,怎么做?
当前回答
确定. .可以简单地使用key属性在任何时候强制重新呈现(重新创建)。
<mycomponent :key="somevalueunderyourcontrol"></mycomponent>
有关示例,请参见https://jsfiddle.net/mgoetzke/epqy1xgf/
这里也有讨论:https://github.com/vuejs/Discussion/issues/356#issuecomment-336060875
其他回答
为我工作
data () {
return {
userInfo: null,
offers: null
}
},
watch: {
'$route'() {
this.userInfo = null
this.offers = null
this.loadUserInfo()
this.getUserOffers()
}
}
为了重新加载/重新渲染/刷新组件,停止长编码。Vue.JS可以做到这一点。
只需使用:key属性。
例如:
<my-component :key="unique" />
我正在使用BS Vue表槽。我要为这个组件做一些事情,让它是唯一的。
<my-component :key="uniqueKey" />
同时使用。$set(obj,'obj_key',value) 并且每次更新object (obj)值时更新uniqueKey 对于每一次更新this. uniquekey++
这对我来说很管用
除了页面重载方法(闪烁),没有一个适合我(:键没有工作)。
我发现这个方法从旧vue.js论坛,这是为我工作:
https://github.com/vuejs/Discussion/issues/356
<template>
<div v-if="show">
<button @click="rerender">re-render</button>
</div>
</template>
<script>
export default {
data(){
return {show:true}
},
methods:{
rerender(){
this.show = false
this.$nextTick(() => {
this.show = true
console.log('re-render start')
this.$nextTick(() => {
console.log('re-render end')
})
})
}
}
}
</script>
使用vm。美元(varName,价值)。
在Change_Detection_Caveats中查看详细信息