前言
这是一个非常非常有用的东西,大家在用vue开发项目的时候应该会遇到要刷新一下组件的需求,如果大家用的js的方法,就很没有用户体验感,这个方法是通过$nextTick来进行一个刷新,我把它封装到了app.vue中,用的时候就很方便,大家看到了就都了解一下吧
一、在App.vue中写
<template>
<router-view v-if="isRouterAlive"></router-view>
</template>
<script>
export default{
provide(){
return{
reload:this.reload
}
},
data(){
return{
isRouterAlive:true
}
},
methods:{
reload(){
this.isRouterAlive=false;
this.$nextTick(function(){
this.isRouterAlive = true;
})
}
}
}
</script>
二、在需要刷新的组件中写入
<script>
export default{
inject:["reload"],
methods:{
fn(){
this.reload()
}
}
}
</script>
结语
也是挺清晰的,用起来也非常的好用,希望对你有所帮助