我正在尝试重定向页面,但我得到一个错误。我认为我的定义是正确的,为什么我得到这个错误?
提前感谢你的帮助,谢天谢地你来了。
router.js
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router);
import Homepage from './screens/Homepage';
import Journey from './screens/Journey';
const router = new Router({
mode: 'history',
routes: [
{
path: '/',
component: Homepage
},
{
path: '/journey',
component: Journey
}
]
});
export default router;main.js
import Router from './router';
new Vue({
store: Store,
router: Router,
el: '#app',
render: h => h(App)
});我的推送..
this.$router.push('/journey');发布于 2020-07-09 07:42:14
我认为在编写this.$router.push('/journey');的地方,this关键字是未定义的。因此,为了避免在块范围的顶部出现这种情况,您可以将this关键字赋给一个变量,然后使用该变量而不是this。
// Declare this at the top or first line of the function or block scope
let self = this
.
.
.
.
self.$router.push('/journey');https://stackoverflow.com/questions/62804938
复制相似问题