【问题标题】:Get props from another state in Vue从 Vue 中的另一个状态获取道具
【发布时间】:2020-10-21 08:02:12
【问题描述】:

这里我有两条路线,即预约和医生。在医生中,我希望在单击Book Now 按钮(image-1)时,其中的参数替换选择选项(image-2)的值

我的路线:

const router = new VueRouter({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'appointment',
      component: Appointment
    },
    {
      path: '/doctors',
      name: 'doctor',
      component: Doctor
    },
  ],
})

Image-1 视图: 医生,这里显示医生的数据。

Image-1 代码:当按钮被点击时,它会移动到路线预约并根据发送的参数替换选择选项的值,这里是我的代码:

<router-link :class="['btn btn-sm btn-success ml-1 p-1']" :to="{ 
    name: 'appointment', 
    params: {   
                book_hospital_id: item.hospitals.id, 
                book_specialist_id: item.specialists.id , 
                book_doctor_id: item.doctors.id  
            } 
}">Book Now</router-link>

Image-2 视图: 发送的参数将替换 select 选项,如下所示。

Image-2 代码:

data: function () {
    return {
        optHospital: '',
        optSpeciality: '',
        optDoctor: '',
    }
},

【问题讨论】:

  • 可以在mounted方法中设置。 this.optHospital=this.$route.params.book_hospital_id;等等……

标签: javascript vue.js vuejs2 vue-router


【解决方案1】:
<router-link :class="['btn btn-sm btn-success ml-1 p-1']" :to="{ 
    name: 'appointment', 
    props: true,
    params: {   
                book_hospital_id: item.hospitals.id, 
                book_specialist_id: item.specialists.id , 
                book_doctor_id: item.doctors.id  
            } 
}">Book Now</router-link>

VueRouter: Passing Props to Route Components

VueRouter: Passing Props to Route Components - Boolean mode

【讨论】:

  • 感谢参考,以后会详细了解
猜你喜欢
  • 2021-01-31
  • 2020-12-21
  • 2023-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-05
  • 2020-05-13
  • 2021-02-10
相关资源
最近更新 更多