vue.js路由学习笔记二
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.js"></script> <script src="https://cdn.bootcss.com/vue-router/3.0.1/vue-router.js"></script> </head> <body> <div id ="app"> <div> <router-link to="/home">主页</router-link> <router-link to="/news">新闻</router-link> </div> <router-view></router-view> </div> </body> <script> var Home=Vue.extend({ template:'<h3>我是主页</h3>' }); var News=Vue.extend({ template:'<h3>我是新闻</h3>' }); var router =new VueRouter({ routes :[ {path:'/home',component:Home}, {path:'/news',component:News}, {path:'/',component:Home} ] }); var vm=new Vue({ router }).$mount('#app'); </script> </html>
运行结果:
笔记转移,由于在有道云的笔记转移,写的时间可能有点久,如果有错误的地方,请指正