zoukankan      html  css  js  c++  java
  • vue-roter2 路由传参

    使用vue开发项目,在使用vue-router做路由时,经常遇到需要在新路由到页面中需要使用之前页面的一些数据, 比如从列表页到详情页.

    本文主要介绍通过vue-router2路由中传参的方法,项目为vue-cli搭建项目

    1.路由配置

    首先在路由配置处(router/index.js), 在path后面通过:+参数名来指定参数名

    需要注意的是此处的name为必须

    1 const router = new VueRouter({
    2   routes: [
    3     {
    4       path: '/user/:userId',
    5       name: 'user',
    6       component: User
    7     }
    8   ]
    9 })

    2.router-link 传参

    在对应的html代码中,给 router-link 的 to 属性传一个对象

    1 <router-link :to="{ name: 'noticeDetail', params: { id: 333}}"><span class="notice_title">{{notice.title}}</span></router-link>

    这种方式会把路由导航到 /noticeDetail/333 路径。

    3.接收参数

    在路由到的新页面下,在mounted下接收参数

    1    mounted(){
    2       this.id = this.$route.params.id;4     }
  • 相关阅读:
    youtube-VisualSfM and MeshLab workflow video-meshlab part integration
    testing_lab1
    homework2-st
    homework1-spm
    homework1-st
    just one last blog
    week 10
    week 9
    week 8
    课后题7
  • 原文地址:https://www.cnblogs.com/yuqing6/p/7157526.html
Copyright © 2011-2022 走看看