问题描述
微信小程序的tabbar,写成组件,然后再index页面(主页面)中以v-if的形式进行选择展示。因为是组件级页面,不具有onshow的生命周期钩子,当数据发生变化的时候,组件内的数据并没有变化。例如:组件在created是获得缓存数据后,缓存中的数据变化时。
解决方法
使用$.nextTick()方法进行子组件刷新;
<tempalte>
<!-- 我的 -->
<w-mine v-if="refresh" />
</tempalte>
<script>
export default {
data() {
return {
refresh: true,
}
},
onShow() {
this.refresh = false;
this.$nextTick(() => {
this.refresh = true;
})
}
}
</script>
点赞 评论 收藏 ~~ 有疑惑的小伙伴,可能是我表达不清楚,可以留言讨论,如有错误,也希望大家不吝指出。 ~~ 点赞 评论 收藏