zoukankan      html  css  js  c++  java
  • Vue动态路由


    Vue动态路由
    1、不同路由传值:动态路由

    1、配置动态路由

    routes: [
    // 动态路径参数 以冒号开头
    { path: '/user/:id', component: User }
    ]


    2、在对应的页面

    this.$route.params获取动态路由的值
    var aid=this.$route.params.aid;
    this.$route.query //获取get传值 

    //第一种跳转方式
    // this.$router.push({ path: 'news' })
    // this.$router.push({ path: '/content/495' });


    //另一种跳转方式
    // { path: '/news', component: News,name:'news' },
    // router.push({ name: 'news', params: { userId: 123 }})
    this.$router.push({ name: 'news'})

    https://router.vuejs.org/


    vue路由配置:


    1.安装

    npm install vue-router --save / cnpm install vue-router --save


    2、引入并 Vue.use(VueRouter) (main.js)

    import VueRouter from 'vue-router'

    Vue.use(VueRouter)


    3、配置路由

    1、创建组件 引入组件


    2、定义路由 (建议复制s)

    const routes = [
    { path: '/foo', component: Foo },
    { path: '/bar', component: Bar },
    { path: '*', redirect: '/home' } /*默认跳转路由*/
    ]

    3、实例化VueRouter

    const router = new VueRouter({
    routes // (缩写)相当于 routes: routes
    })

    4、挂载


    new Vue({
    el: '#app',
    router,
    render: h => h(App)
    })



    5 、根组件的模板里面放上这句话 <router-view></router-view>


    6、路由跳转
    <router-link to="/foo">Go to Foo</router-link>
    <router-link to="/bar">Go to Bar</router-link>

  • 相关阅读:
    C++中整型变量的存储大小和范围
    A1038 Recover the Smallest Number (30 分)
    A1067 Sort with Swap(0, i) (25 分)
    A1037 Magic Coupon (25 分)
    A1033 To Fill or Not to Fill (25 分)
    A1070 Mooncake (25 分)
    js 获取控件
    C#代码对SQL数据库添加表或者视图
    JS 动态操作表格
    jQuery取得下拉框选择的文本与值
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/11070661.html
Copyright © 2011-2022 走看看