学无先后,达者为师

网站首页 Vue 正文

vue中路由跳转怎么携带参数

作者:调调啊 更新时间: 2022-11-08 Vue

A组件点击跳到B组件 , 携带参数过去

A组件中 (传参)

这里的Bpage是router --> index.js中B页面配置的name

 

 <div v-for="(item, index) in list" :key="index" @click="toDetail(item.username)">
        {{ item.title }}
  </div>





 toDetail(info) {
        this.$router.push({
          name: "Bpage",
          //params是个对象 , 可以写很多个参数传过去
          params: {
            uName:info
          }
        })
 }

B组件(接收参数)

 mounted() {
     
      this.userName= this.$route.params.uName
      
 },

 data() {
      return { 
        userName: ""
      }
    },

原文链接:https://blog.csdn.net/weixin_49577940/article/details/121905577

栏目分类
最近更新