vue路由引入步骤

vue路由引入步骤:

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title></title>
  <style>
    .base{
      width:320px;
      height:300px;
      background:#ddd;
      border:3px solid #1b6d85;
      padding:12px;
      text-align: center;
    }
  </style>
</head>
<body>
<div id="app">
  <!--2:显示不同组件信息-->
  <router-view></router-view>
</div>
<script src="js/vue.min.js"></script>
<!--1:引入路由插件-->
<script src="js/vue-router.js"></script>
<script>
  //3:组件多个组件
  var testLogin = Vue.component("login",{
    template:`
      <div class="base">
          <h1>这是登录页面</h1>
      </div>
    `
  });
  var testRegister = Vue.component("regiter",{
    template:`
      <div  class="base">
         <h1>这是注册页面</h1>
      </div>
    `
  });
  //4:配置路由词典
  //语法: 请求路径       对应组件
  //{path:"/login",component:testLogin}
  //当path为空:相当于指定页面打开时,默认加载组件
  const myRoutes = [
    {path:"",component:testLogin},
    {path:"/login",component:testLogin},
    {path:"/reg",component:testRegister}
  ];
  //5:创建由路对象
  const myRouter = new VueRouter({
    routes:myRoutes
  });
  //6:创建Vue对象,并且指定路由对象
  new Vue({
    router:myRouter,
    el:"#app"
  });
</script>
</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值