VueRouter3总结

知识点:

配置路由:第一步安装! 不行可以指定版本:

npm install --legacy-peer-deps vue-router@3.5.2

首先我们要 创建一个 router.js文件

  1. 引入Vue 引入VueRouterVueRouter  useVue
  2. // 引入Vue
    import Vue from "vue";
    // 引入VueRouter
    import VueRouter from "vue-router";
    // 将VueRouter挂在到Vue上
    Vue.use(VueRouter);
  3. 配置路径
  4. import itemOne from "@/components/itemOne";
    import itemTwo from "@/components/itemTwo";
    
    // 配置路径
    const routes = [
      { path: "/", component: itemOne },
      { path: "/itemOne", component: itemOne },
      { path: "/itemTwo", component: itemTwo },
    ];

    首先要引入文件夹, 在配置routes 注意是一个对象形式 里面的 path代表自定义路径名字,component:代表import 引进来的文件名字。

  5. new 一个VueRouter({  }) 这里面参数 第一个是routes 配置的路径 mode:路径的模式
  6. const router = new VueRouter({ routes: routes, mode: "history" });

    1.hash  显示的网络路径中会有#号,这是最安全的模式,因为他兼容所有的浏览器和服务器  2.history 路径中会去掉 # 号 注意IE9一下的版本                                                                      3.abstract  适用于全部的JavaScript环境。 列如服务端使用Node.js

  7. 最后导出router 

  8. 在main.js 里面引入 router             后在new Vue 上面使用 router

  9. //用来跳转页面  类似于a 但页面跳转页面不会刷新
    <router-link to="/itemOne">跳转</router-link>
    //用来存放跳转的页面
    <router-view></router-view>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值