1.在App.vue写入
<template>
<div id="app">
<router-view v-if="isRouterAlive"></router-view>
<!-- <router-view/> -->
</div>
</template>
<script>
export default {
name: 'App',
provide () { //父组件中通过provide来提供变量,在子组件中通过inject来注入变量。
return {
reload: this.reload
}
},
data() {
return{
isRouterAlive: true //控制视图是否显示的变量
}
},
methods: {
reload () {
this.isRouterAlive = false; //先关闭,
this.$nextTick(function () {
this.isRouterAlive = true; //再打开
})
}
}
}
</script>
2.想要刷新的页面
export default {
inject:['reload'], //注入App里的reload方法
data() {
return {
// 获取vuex中的标签
tags: [],
};
},
3.想要刷新处
this.reload(); //此处this是由作用域限制指向问题
如下是例子
var that = this;
api.updateTag({
"id":item.id,
"typeName": value
}).then(
function(res) {
that.reload();
this.$message.success("你的修改的新标签名是: " + value);
},
function(err) {
console.log(err)
}
)