只是一个简单的问题。
你能强迫Vue.js重新加载/重新计算所有内容吗?如果有,怎么做?
只是一个简单的问题。
你能强迫Vue.js重新加载/重新计算所有内容吗?如果有,怎么做?
当前回答
添加:key到vue-router库的router-view组件的方法会引起我的fickers,所以我使用vue-router的“组件内保护”来拦截更新,并在同一路由上的路径更新时相应地刷新整个页面(如$router. exe)。美元,路由器。推,路由器。替换也无济于事)。唯一需要注意的是,通过刷新页面,我们暂时打破了单页应用行为。
beforeRouteUpdate(to, from, next) {
if (to.path !== from.path) {
window.location = to.path;
}
},
其他回答
这对我来说很有效。
created() {
EventBus.$on('refresh-stores-list', () => {
this.$forceUpdate();
});
},
另一个组件触发refresh-stores-list事件将导致当前组件重新呈现
使用vm。美元(varName,价值)。
在Change_Detection_Caveats中查看详细信息
使用v-if指令
<div v-if="trulyvalue">
<component-here />
</div>
因此,简单地将truyvalue的值从false更改为true将导致div之间的组件重新渲染
请读一读 http://michaelnthiessen.com/force-re-render/
可怕的方式:重新加载整个页面 更好的方法:使用Vue的内置 最好的方法:在你的 组件
<template>
<component-to-re-render :key="componentKey" />
</template>
<script>
export default {
data() {
return {
componentKey: 0,
};
},
methods: {
forceRerender() {
this.componentKey += 1;
}
}
}
</script>
在某些情况下,我也用watch。
为了重新加载/重新渲染/刷新组件,停止长编码。Vue.JS可以做到这一点。
只需使用:key属性。
例如:
<my-component :key="unique" />
我正在使用BS Vue表槽。我要为这个组件做一些事情,让它是唯一的。