zoukankan      html  css  js  c++  java
  • vue-router

    router常见参数如下

      一,mode:hash   与 history 

             hash模式下 页面的地址会加上#号更变路由

             history模式下 路由与平常的页面一样

     二, base: 应用的基路径, 比如整个单页应用服务在 /page/app/ 下,那么base就应该设置为 /page/app/. 一般写成 __direname(在webpack中有配置),当然你也可以写成 /page/app/

        三, 引入组件有一种懒加载方式,当访问该页面才会加载相关资源 这样能提高页面访问速度

        component: resolve => require(['@/views/HelloWorld'], resolve) // 使用懒加载

     四,router传参

    {
      path: '/helloworld/:name', // 对路径做拦截,这种类型的链接后面的内容会被vue-router映射成name参数了
      name: 'HelloWorld',
      component: resolve => require(['@/views/HelloWorld'], resolve) // 使用懒加载
    }

    get请求参数:http://localhost:8080/helloworld?aaa=1

    我们可以取到aaa的参数

    let aaa = this.$route.query.aaa; //问号后面参数会被封装进 this.$route.query;
    console.log(aaa); // 打印出1

    可以通过监听this.$route获取参数变化

      五、路由跳转

    <router-link to="/demo">点击我跳转</router-link>
    this.$router.push('/demo');

    传参跳转:
    <router-link :to="{path: '/demo', query:{'id': 22, 'name': 'kongzhi'}}">
      点击我跳转
    </router-link>
    this.$router.push({path: '/demo'});


  • 相关阅读:
    推荐随笔
    搭建http服务
    python之numpy和pandas
    eclipse项目打包
    keras安装
    eclipse设置快速提示符
    linux常用命令
    Webpack3 从入门到放弃
    【ES6】Generator+Promise异步编程
    【Vue】删除数组元素,导致剩余元素被重新渲染
  • 原文地址:https://www.cnblogs.com/moneyss/p/8618533.html
Copyright © 2011-2022 走看看