设置router/index.js:
import Vue from 'vue'
import HelloWorld from '@/components/HelloWorld'
import Index from '../../static/Index'
import Router from 'vue-router'
Vue.use(Router)
const router = new Router({
routes: [
{path: '/', name: 'Index',meta:{title:'登陆'}, component: Index}
]
})
router.beforeEach((to, from, next) => {//beforeEach是router的钩子函数,在进入路由前执行
if (to.meta.title) {//判断是否有标题
document.title = to.meta.title
}
next()//执行进入路由,如果不写就不会进入目标页
})
export default router;