<!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>

运行结果:

vue.js路由学习笔记二

 

相关文章:

  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2021-06-09
猜你喜欢
  • 2021-10-16
  • 2021-06-22
  • 2021-10-31
  • 2021-11-25
  • 2022-01-02
  • 2021-03-30
  • 2021-12-15
相关资源
相似解决方案