我使用 Vue 和 Ionic,我不知道如何將我的課程 ID 傳遞給方法 openModal()
解釋:我有一張卡片,里面有我的資料 - 課程資料,其中還有評論,當用戶點擊它們時,模態視窗是打開的,我需要將課程的 id 作為道具傳遞給我的模態視窗,以便我可以顯示評論課程。
<ion-content>
<div
v-for="lesson in lesson.video_lessons"
:key="lesson"
>
<div >
<h2>{{ lesson.content_description }}</h2>
<div >
<span v-for="tag in lesson.tags" :key="tag">
#{{ tag }}
</span>
</div>
<img
v-if="lesson.content_thumbnail"
:src="`${lesson.content_thumbnail}`"
alt="如何將 id 傳遞給模態視窗組件"
height="600"
/>
</div>
<div >
<a href="#">bookmark</a>
<a href="#">heart</a>
<p>{{ lesson.likes }}</p>
<a @click="openModal">comments</a>
<p>lesson id: {{ lesson.id }}</p>
</div>
</div>
</ion-content>
這是我的方法
async openModal() {
const modal = await modalController.create({
component: CommentsModal,
componentProps: { id: 1 }, // i need to replace this 1 with id of the lesson
})
return modal.present()
},
uj5u.com熱心網友回復:
在模板中,像這樣傳遞它
<a @click="openModal(lession.id)">comments</a>
并在方法中
async openModal(payload) { // change added
const modal = await modalController.create({
component: CommentsModal,
componentProps: { id: payload}, // Change added
})
return modal.present()
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/358040.html
