vue-vue页面之间的传值
1. router-link标签跳转#
- 不需要传参
<router-link to='two'><button>点我到第二个页面</button></router-link>
-
id传参
-
传参页面
<!--<router-link :to="{'path':'/要跳转的路由/','query':{'id':sect.id}}">上传课程</router-link>-->
-
跳转页面
data() { return { course:{}, id :this.$route.query.id+ "/" , #从路由中获取参数id }, }
-
2.点击事件跳转#
- 不需要传参
html :
<button @click="hreftwo" class="test-one">点我到第二个页面</button>js :
methods:{
//跳转页面
hreftwo(){
this.$router.push({path:'/two'})
}
}
-
需要传参
- 传参页面
<template> <div> <div v-for="good in goods"> <a>标题:{{good.title}}</a> <a v-if="uid">价格:{{good.v_price}}</a> <a v-else>价格:{{good.price}}</a> <a><img :src="'http://127.0.0.1:8000/'+good.img" style="width: 100px"></a> <button @click="add_order(good.title,good.price)">提交订单</button> <!--<router-link :to="{'path':'/order/','query':{'title':good.title,'price':good.price}}">提交订单</router-link>--> <div style="border:1px solid #CCC"></div> </div> </div> </template> <script> export default { name: "GoodsLIst", data() { return { goods: [], title:'', price:'' } }, methods: { add_order(title,price) { if (!this.uid) { this.$router.push('/login') } else { <!--// http://127.0.0.1:8080/order?title=***&price=***--> this.$router.push({path:'/order?title='+title+'&price='+price}) } } } } </script> <style scoped> </style>
- 跳转页面可以在要跳转的页面上使用this.$route.query.id, 从路由中获取参数
data() { return { course:{}, id :this.$route.query.id+ "/" , #从路由中获取参数id }, }
作者:就学45分钟
出处:https://www.cnblogs.com/tjw-bk/p/13823312.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了