美文网首页
路由跳转 页面字段不刷新

路由跳转 页面字段不刷新

作者: 微笑的大步向前走 | 来源:发表于2019-10-08 13:26 被阅读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

    相关文章

      网友评论

          本文标题:路由跳转 页面字段不刷新

          本文链接:https://www.haomeiwen.com/subject/wddbpctx.html