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
          },
    }
    
posted @   就学45分钟  阅读(746)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示
主题色彩