vue Router 动态路由传值 与Get传值

方式一:动态路由传值

1、定义路由规则

import Newcontent from './components/NewContent.vue';
//2、配置路由
const routes = [
{ path: '/new', component: News },
{ path: '/blog', component: Blog },
//动态路由传值
{ path: '/newcontent/:Id', component: Newcontent },
//表示如果没有匹配上路由就跳转到new
{ path: '/*', redirect: '/new' }
]

2、拼接数据链接

<ul v-for="(item,key) in list">
    <li >
        <router-link :to="'/newcontent/'+key"> {{item}}</router-link>
       
    </li>
    
</ul>

注意:绑定动态数据是:冒号,并且是拼接字符串。这样就可以实现动态绑定路由传值

3、获取动态路由传递值

this.$route.params.Id

方式二:get传值

1、配置路由

//2、配置路由
const routes = [
{ path: '/new', component: News },
{ path: '/blog', component: Blog },
//get传值
{ path: '/newcontent', component: Newcontent },
//表示如果没有匹配上路由就跳转到new
{ path: '/*', redirect: '/new' }
]

2、数据格式
<h2>Get传值</h2>
<ul v-for="(item,key) in list">
    <li >
        <router-link :to="'/newcontent?Id='+key"> {{item}}</router-link>
       
    </li>
    
</ul>

 

 

3、获取传值方式

this.$route.query

 

 

以上两种方式传值,传值是注意拼接链接

转载于:https://www.cnblogs.com/daiyekun-blog/p/10146483.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中,可以通过路由参数和查询参数来实现路由跨页面传值。 如果你想在路由之间传递参数,可以使用路由参数。在配置路由时,可以在路由节点中定义参数,然后在目标组件中通过`this.$route.params`来获取传递的参数。例如,在`index.js`中配置路由节点时,可以定义一个参数`id`,然后在目标组件中通过`this.$route.params.id`来获取该参数的值。\[1\] 如果你想在路由之间传递查询参数,可以使用查询参数。在路由路径中使用`?`加上参数名和参数值的形式来传递查询参数。在目标组件中,可以通过`this.$route.query`来获取传递的查询参数。例如,在模板中使用`<router-link to="/?id=1000&name=abcd">Home</router-link>`来传递查询参数,然后在目标组件中通过`this.$route.query`来获取这些参数的值。\[3\] 总结起来,Vue路由夸界面传值可以通过路由参数和查询参数来实现。使用路由参数可以在路由节点中定义参数,并在目标组件中通过`this.$route.params`来获取参数的值。使用查询参数可以在路由路径中使用`?`加上参数名和参数值的形式来传递参数,并在目标组件中通过`this.$route.query`来获取参数的值。 #### 引用[.reference_title] - *1* *3* [vue路由的get传值详解](https://blog.csdn.net/weixin_47863547/article/details/119189387)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [vue路由的动态传值详解](https://blog.csdn.net/weixin_47863547/article/details/119185414)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值