Vue Router 是 Vue.js 官方的路由管理器。它和 Vue.js 的核心深度集成,讓構建單頁面應用變得易如反掌。包含的功能有:javascript
<!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> <script src="https://cdn.bootcss.com/vue/2.5.22/vue.min.js"></script> <!--一、引入vue-router(核心插件)--> <script src="https://cdn.bootcss.com/vue-router/3.0.2/vue-router.min.js"></script> </head> <body> <div id="app"></div> <script type="text/javascript"> let Login = { template:`<div> <h1>我是登陸界面</h1> </div>` } let Register = { template: `<div> <h1>我是註冊界面</h1> </div>` } //二、安裝插件 =>? Vue.use(VueRouter); //三、建立路由對象 let router = new VueRouter({ //四、配置路由對象 routes:[{ path:"/login", component:Login },{ path:"/register", component:Register }] }) //五、將配置好的路由對象關聯到vue實例中 let App = { template:` <div> <!--vue內置組件--> <router-link to="/login">登陸</router-link> <router-link to="/register">註冊</router-link> <router-view></router-view> </div>` } new Vue({ el:"#app", template:`<app/>`, components:{ app:App }, router:router }) </script> </body> </html>
執行效果css
具體使用請參考html