我已经使用了这个 Vue.js 路由示例应用程序。
https://github.com/chrisvfritz/vue-2.0-simple-routing-example
在src/main.js
我有这么多数据值(value)。
const app = new Vue({
el: '#app',
data: {
currentRoute: window.location.pathname,
token : "",
errorMessage : '', etc...etc..
},
现在使用 socket.io,我将 token 设置为 "sdawdda2d2ada2ad22ad"
当应用程序启动时,currentRoute 等于 "/"
没问题,第一页已加载。 src/routes.js
'/': 'Home',
'/about': 'About'
当我想检查/about (url: localhost:8080/about
) 时,效果很好,但 token 和错误消息再次为空,因为应用程序再次创建。
如果我想在不丢失 token 值的情况下更改页面,我可以使用:
this.currentRoute = "/about" (url: localhost:8080)
它运行良好,但 url 没有改变,所以我不能在浏览器中使用后退按钮。 如果我不想在浏览器转到/about 时丢失 token 值,我该如何分离我的 Vue 应用程序?
非常感谢!
最佳答案
你可以做类似this.$router.go(-1)
或vm.$router.go(-1)
的事情来继续this .$router.go(1)
更多click here
关于javascript - 带后退按钮的 Vue.js 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40182536/