1、 在app.vue設定reload,讓組件重新加載。
<template>
<div id="app">
<router-view v-if="isRouterAlive" />
</div>
</template>
<script>
export default {
name: 'App',
provide () {
return {
reload: this.reload
}
},
data () {
return {
isRouterAlive: true
}
},
methods: {
reload () {
this.isRouterAlive = false
this.$nextTick(function () {
this.isRouterAlive = true
})
}
}
}
《以上是app.vue中的部分設定》
然后在需要重繪的組件中呼叫即可
export default {
name: 'Layout',
inject: ['reload'],
components: {
Navbar,
Sidebar,
AppMain,
HeadMenu
},
methods: {
flush() {
this.reload() //通過inject注入進來的
}
}
《以上是需要被重繪的頁面》
2、如果需要重繪的頁面是引入的子組件,那可以通過修改父組件系結的key值重繪
<comfir :key='num'></comfir>
changeChild(){
this.num=Matn.random();
}
在引入的組件上系結一個key,當key值更新時,子組件也會更新
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/12114.html
標籤:JavaScript
