一、我这边scripts的运行命令是dev,所以npm run dev,打开访问http://localhost:300/就能顺利访问
二、安装路由npm i vue-router@next
在src文件夹下新建router/index.js文件和views/Home.vue文件
//router/index.js页面代码
import { createRouter, createWebHashHistory } from 'vue-router'
const router = createRouter({
history: createWebHashHistory(), // hash模式:createWebHashHistory,history模式:createWebHistory
routes: [
{
path: '/',
redirect: '/home'
},
{
path: '/home',
name: 'home',
component: () => import('../views/Home.vue'),
meta: {
index: 1
}
}
]
})
export default router
//iews/Home.