Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同一个地址只变化id,页面不重载,怎么解决?? #469

Closed
berwin opened this issue Apr 19, 2016 · 11 comments
Closed

同一个地址只变化id,页面不重载,怎么解决?? #469

berwin opened this issue Apr 19, 2016 · 11 comments

Comments

@berwin
Copy link

berwin commented Apr 19, 2016

比如我有一个路由是 /content/:id,当我冲 /content/123 跳转到 /content/456 的时候,页面不会重载,这个问题怎么解决???

@yyx990803

@horizon0514
Copy link

data 钩子会被再次触发,可以在data()中进行处理。 #296

@berwin
Copy link
Author

berwin commented Apr 20, 2016

问题已经解决啦。使用的canReuse

@berwin berwin closed this as completed Apr 20, 2016
@fnlctrl
Copy link
Member

fnlctrl commented Apr 20, 2016

canReuse不优雅 因为会重新渲染整个组件 建议使用data
http://vuejs.github.io/vue-router/en/pipeline/data.html

@laoxubuer
Copy link

@fnlctrl 我在data钩子里请求数据,在浏览器地址栏更改params,data会重新请求,但是视图却并没有更新,不知道问题在什么地方

@hubinjie
Copy link

hubinjie commented Jul 2, 2016

好了,整体改了一下,改成 http://vuejs.github.io/vue-router/en/pipeline/data.html 就好了, 感谢 @fnlctrl

@tipmao
Copy link

tipmao commented May 8, 2017

Hi vue 2.0 如何解决这个问题? 另外上面的 vue-router的参考信息现在都链接不过去.

@biyuehui
Copy link

biyuehui commented Dec 4, 2017

同上,vue2.0怎么解决这个问题,我试着用$router.go()去跳转路由,但是会刷新整个页面而不是路由组件部分,谢谢!

@JounQin
Copy link
Contributor

JounQin commented Dec 4, 2017

use beforeRouteUpdate

@Skura23
Copy link

Skura23 commented Mar 31, 2019

在vue单页面中项目开发中遇到一个问题,侧边栏有一个列表,点击列表选项会跳转动态路由刷新右边的页面。当第一次点击侧边列表的时候,页面动态路由会正常跳转,而跳转后再次点击其他列表项,动态路由中的id会发生相应的变化,但页面不会刷新,依然保持在第一次点击列表项进入的某个页面。

出现这种情况是因为依赖路由的params参数获取写在created生命周期里面,因为相同路由二次甚至多次加载的关系 没有达到监听,退出页面再进入另一个文章页面并不会运行created组件生命周期,导致文章数据还是第一次进入的数据。解决办法是:
watch: { 
'$route' (to, from) {   
//监听路由是否变化     
//在这里可以处理对应的跳转逻辑 
}

作者:苏泞
链接:https://www.jianshu.com/p/d20a06f79476
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

@fyzhu
Copy link

fyzhu commented Oct 16, 2019

以上所有文章的链接都打不开了😓

@vuejs vuejs locked as resolved and limited conversation to collaborators Oct 16, 2019
@posva
Copy link
Member

posva commented Oct 16, 2019

Locking as this is issue is really outdated now

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests