1. 首先先要在根目录下 download vue和vue-router
npm i vue vue-router -D
2. 基本代码演示
-
操作文件
-
demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
{{ msg }}
<!-- 路由占位 -->
<router-view></router-view>
</div>
<script src="vue.js"></script>
<script src="vue-router.js"></script>
<script>
// 登陆组件配置项
var LoginComponent = {
template: `<div>{{ msg }}</div>`,
data() {
return { msg: "我是登陆页面" }
}
};
// 注册组件配置项
var RegisterComponent = {
template: `<div>{{ msg }}</div>`,
data() {
return { msg: "我是注册页面" }
}
};
new Vue({
el: '#app',
data: {
msg: '路由演示'
},
// 路由配置
router: new VueRouter({
// 路线配置
routes: [
{ path: '/login', component: LoginComponent },
{ path: '/register', component: RegisterComponent }
]
})
});
</script>
</body>
</html>
网友评论