[ADD]vue-router的使用

This commit is contained in:
viletyy 2020-10-11 17:46:11 +08:00
parent 4a6f0067b1
commit f44264f8d8
1 changed files with 92 additions and 0 deletions

92
vue-router/router.html Normal file
View File

@ -0,0 +1,92 @@
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div id="app">
<h1>hello app!</h1>
<p>
<router-link to="/home">主页</router-link>
<router-link to="/user">用户</router-link>
</p>
<router-view></router-view>
</div>
<template id="user">
<div>
<h3>用户信息</h3>
<ul>
<router-link to="/user/login?name=tom&pwd=123" tag="li">用户登录</router-link>
<router-link to="/user/regist/alice/456" tag="li">用户注册</router-link>
</ul>
<router-view></router-view>
</div>
</template>
<script>
var Home = {
template: '<h3>我是主页</h3>'
}
var User = {
template: '#user'
}
var Login = {
template: '<h4>用户登录。。。{{$route.query}}, {{$route.path}}</h4>'
}
var Regist = {
template: '<h4>用户注册。。。{{$route.params}}, {{$route.path}}</h4>'
}
const routes = [
{
path: '/home',
component: Home
},
{
path: '/User',
component: User,
children: [
{
path: 'login',
component: Login
},
{
path: 'regist/:username/:password',
component: Regist
}
]
},
{
path: '*',
component: Home
}
]
const router = new VueRouter({
routes
})
const app = new Vue({
router
}).$mount('#app')
</script>
</body>
</html>