社區
在我的應用程式中,我呈現了一個醫生串列。此串列顯示在我的 DoctorView 組件中,如下所示:
<div
class="col-12 m-2"
v-for="recommendation in recommendations"
:key="recommendation"
>
<DoctorListItem :recommendation="recommendation" />
</div>
我想要做的是,當用戶單擊此串列中的條目時,我希望應用程式打開有關該醫生的詳細資訊頁面。所以在我的 DoctorListItem 組件中,我使用了一個路由器鏈接:
<router-link
:to="`/doctors/${recommendation.doctor.doctor_id}`"
class="stretched-link"
></router-link>
現在我需要將此 id 提供給 ReadDoctorView,它顯示有關所選醫生的詳細資訊。因為我需要這些資訊來加載所選醫生的詳細資訊。這個 id 在我的 DoctorView 和我的 DoctorListItem 中可用,但我無法將它獲取到我的 ReadDoctorView 組件。我用道具嘗試過這個,但我是一個絕對的初學者,我不確定在哪里定義道具以及如何處理資料。
在我的 ReadDoctorView 中,我需要一種類似于下面的方法來獲取選定的醫生:
methods: {
getDoctorById() {
this.id = this.recommendation.doctor.doctor_id;
console.log(this.id);
return axios
.get('http://URL/doctors/${this.id}')
.then((response) => {
this.doctordetails = response.data;
console.log(id);
})
.catch((error) => {
console.log("Ein Fehler ist aufgetreten: " error.response);
});
},
},
我希望我的解釋是有道理的,你能理解我想要完成的任務。預先感謝您提供任何提示!
PS:我收到這些警告是因為 vue 路由器不知道這些路由。知道如何停止這些警告:

uj5u.com熱心網友回復:
在 Vue 路由引數中,可以通過訪問 $router 物件來訪問路由,嘗試使用解決方案訪問我希望它會起作用:
this.id = this.$route.params.id
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/372763.html
標籤:javascript Vue.js 使成为 Vue道具
上一篇:將焦點設定在Vue中的輸入欄位上
下一篇:404在nuxt中找不到svg
