Recently, I've been working on implementing a vue2 modal
following the instructions provided in the official Vue documentation at https://v2.vuejs.org/v2/examples/modal.html.
The code snippet I have been using looks something like this:
<tbody v-if="fields.length">
<tr v-for="(item, index) in fields">
<td>@{{ item.name }}</td>
<td><input type="checkbox" id="checkbox" v-model="item.active"></td>
<td>
<button id="show-modal" @click="showModal = true">Show Modal</button>
</td>
</tr>
<modal :item="item" v-if="showModal" @close="showModal = false">
<h3 slot="header">Hello World</h3>
</modal>
</tbody>
Vue.component('modal', {
template: '#modal-template',
data: function() {
return {
item: ''
}
}
});
Even though the button triggers the modal successfully, I encountered a warning stating that
Property or method "item" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
. Additionally, upon inspecting the modal
component using Vue dev tools, the value of item
remains as an empty string ''
, indicating that it is not being populated by the :item
binding as expected.
Could someone guide me on the correct approach to pass the item
object into the modal so it can be utilized within the window?