步骤
一、安装命令:npm install vue-router
二、配置:
1、在mian.js文件中加入代码
import router from “./router”;
new Vue({
router,
render: (h) => h(App),
}).$mount("#app");
2、新建一个router文件夹,下面建个index.js文件,写入代码
import Vue from “vue”;
import VueRouter from “vue-router”;
import Login from “…/view/Login.vue”; //举例跳转到login页面
Vue.use(VueRouter);
const routes = [
{
path: “/login”, //login页面
name: “Login”,
component: Login,
},
];
const router = new VueRouter({
routes: routes,
});
export default router;