首页 > 其他分享 >Vue路由传递参数与接受参数

Vue路由传递参数与接受参数

时间:2022-08-22 21:00:36浏览次数:61  
标签:Vue xxx 参数 props 组件 id 路由

路由(参数传递)

使用路径匹配的方式

  • 修改路由配置
{
    path: '/xxx/xxx/:id',
    component: XXX
}
  • 主要是在 path 属性中增加了 :id 这样的占位符,来接受路由参数

    • 例如 /xxx/xxx/66 ID={{$route.params.id}}

    • 源组件 => 源组件
      // 源组件
      <template>
      	<div>
              <!--写法1-->
              <router-link to="/xxx/xxx/666"></router-link>
              <!--写法2-->
              <router-link :to="{name: '组件Name', params: {id:2} }"></router-link>
              <div>
              	<router-view></router-view>    
          	</div>
          </div>
      </template>
      
      // 目标组件
      <template>
      	<div>
             	<!-- 使用route.params.id 来获取路由参数 -->
              ID={{$route.params.id}}
              <!-- 通过props接受路由参数,前提是在路由配置添加 props属性 -->
              ID={{id}}
          </div>
      </template>
      <script>
      	export default {
              // 通过props来接受路由参数占位,前提是在路由配置添加 props属性,props:true
              props: ['id']
          }
      </script>
      
      

标签:Vue,xxx,参数,props,组件,id,路由
From: https://www.cnblogs.com/bingquan1/p/16614236.html

相关文章

  • 记录vue
    #查看版本node-v#安装Node.js淘宝镜像加速器(cnpm)注意源地址已经改变npminstall-gcnpm--registry=https://registry.npmmirror.comcnpminstallcnpm-g#全局......
  • vue 3 + element UI 表格添加必填星号:*
     使用vue版本:[email protected]使用element-plus版本:[email protected]引用了如下脚本:<scriptsrc="~/lib/vue/vue.global.min.js"></script><linkhref="~/lib/element......
  • vue 3 + element UI 表格分页及增删查改
    使用vue版本:[email protected]使用element-plus版本:[email protected]使用axios版本:[email protected]引用了如下脚本:<scriptsrc="~/lib/vue/vue.global.min.js"></script><li......
  • jwbasta-vue
    平台简介  jwbasta-vue是一套全部开源的快速开发java后台API平台,毫无保留给个人及企业一次性付费使用。采用前后端分离的模式,微服务版本前端基于vue开发(无前端页面)......
  • Vue3+Vite+Vant报错Uncaught SyntaxError: The requested module '/node_modules/.vit
    原因在开发过程中Vue3的依赖版本有变更,直接使用的npminstall下载新的版本,会导致node_modules下存在旧版本的缓存,从而影响了本地项目的启动编译。解决方案删除项目的......
  • vue记录
    #查看版本node-v#安装Node.js淘宝镜像加速器(cnpm)cnpminstallcnpm-g#全局安装vue-clicnpminstallvue-cli-g#查看是否安装成功webpack-v或vuelist#......
  • vue 无限滚动插件
    在线演示:https://chenxuan1993.gitee.io/component-document/index_prod#/component/seamless-otherscnpminstallvue-seamless-scroll--save引入importvueSeamless......
  • 舵机 PID控制参数补充
    PID控制是一种非常有用的工具,可用于微调DYNAMIXEL系统的运动行为,以下视频很好地介绍了PID控制的基础知识。   链接稍后发送虽然这段视频为理解PID控制中使用的参数......
  • Vue新建项目
    输入项目名teset2  自定义安装  选择所需要的包  选择vue版本  选择路由类型,是否选用历史路由(默认hash路由 选择scss  选择标准版eslint ......
  • vue动态添加class 三个以上的条件做判断(转)
    原文:https://blog.csdn.net/Akatsuki233/article/details/100653049:class="{'redRoom':Number(items.status)===1,'greenRoom1':Number(items.status)===2,green......