路由跳转 页面字段不刷新

2019-10-08  本文已影响0人  微笑的大步向前走

需求:
子页面修改之后,跳转到父页面,需要父页面中的某个组件字段进行刷新

现状:
跳转回来之后 ,该组件 没有进行相关字段的代码运行进行数据更新

解决:

所以,在网上查找了一下相关资料:

现在父组件 的相关 组件上 加入了 key 值

父组件:

    <!-- 发布菜单 -->
    <send-menu :isClassroomMessage="isClassroomMessage"
               v-if="isSendMenuShown"
               :key="key" />

js相关:

  computed: {
    key () {
      return this.$route.path + Math.random()
    }
  },

那么该组件(send-menu.vue)中,就会每次都运行 beforeMount() 里面的代码了

  beforeMount () {
    this.hasNoticeMessage = !!JSON.parse(localStorage.getItem('noticeMessage'))
    this.hasTopicMessage = !!JSON.parse(localStorage.getItem('topicMessage'))
    this.hasSurveyMessage = !!JSON.parse(localStorage.getItem('surveyMessage'))
  },

资料:
vue路由切换,页面不更新?你可以试试这个方法:https://blog.csdn.net/weixin_34161064/article/details/91380457

上一篇下一篇

猜你喜欢

热点阅读