[Vue基础实战]路由简单测试

参考代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>路由简单测试-1</title>
</head>
<body>
    <div id="app">
        <router-link to="/login">登录</router-link>
        <router-link to="/register">注册</router-link>
        <router-view></router-view>
    </div>
    <script src="../js/vue.js"></script>
    <script src="../js/vue-router.js"></script>
    <script>
      const loginTmp = Vue.extend({
          template: '<h3>登录组件</h3>',
      });
      const registerTmp = Vue.extend({
          template: '<h3>注册组件</h3>',
      });
      const login=Vue.component('login',loginTmp);
      const register=Vue.component('register',registerTmp);
      const router = new VueRouter({
            routes:[
               { path: '/', redirect: '/login' },
               { path: '/login',component: login },
               { path: '/register',component: register}
            ]
        }); 

      const app = new Vue({
          el: '#app',
          router:router
      });
    </script>    
</body>
</html>

 

posted @ 2021-01-15 11:35  dshow  阅读(27)  评论(0编辑  收藏  举报