V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xia0ta0
V2EX  ›  Vue.js

浏览器点击后退,怎样更新 Vue 的组件状态?

  •  
  •   xia0ta0 · 2016-08-23 11:15:11 +08:00 · 9909 次点击
    这是一个创建于 2803 天前的主题,其中的信息可能已经有所发展或是发生改变。
    现在网站的首页有一个用户消息提示,用户点击后会查看消息。但是当用户后退到首页,消息提示还在。只有刷新页面才能消除。

    请问在哪个生命周期里进行设置?
    6 条回复    2016-08-24 09:34:14 +08:00
    des
        1
    des  
       2016-08-23 11:58:00 +08:00 via Android   ❤️ 1
    监听 popstate 事件,然后主动刷新?
    shyling
        2
    shyling  
       2016-08-23 12:06:30 +08:00   ❤️ 1
    在 route:{
    data:{初始化消息提示为隐藏状态}
    }
    airyland
        3
    airyland  
       2016-08-23 12:37:56 +08:00   ❤️ 1
    点击后为什么不清除掉。。
    xia0ta0
        4
    xia0ta0  
    OP
       2016-08-23 18:07:15 +08:00
    @des 感觉有点不 Vue ...

    @shyling 现在是在一个 component 里, route 方法好像不起作用


    @airyland 想找到一个通用的浏览器后退,页面状态刷新方案
    shyling
        5
    shyling  
       2016-08-23 18:27:56 +08:00
    @xia0ta0 试试 ready ,不然就在外部 component 传 not show 的 prop , vuex 什么的咯
    xia0ta0
        6
    xia0ta0  
    OP
       2016-08-24 09:34:14 +08:00
    @shyling 嗯,看来要放到 store 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5422 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 101ms · UTC 07:53 · PVG 15:53 · LAX 00:53 · JFK 03:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.