P粉2564870772023-08-29 09:56:52
One option is to put the state of each modal in an object. This way, you don't need to add a data attribute to each modal.
If the content inside the modal is similar enough, you can use v-for, using the index as the key in the same way.
<b-modal v-model="modal_states[1]">模态框1</b-modal> <b-button @click="openModal(1)">打开1</b-button> <b-modal v-model="modal_states[2]">模态框2</b-modal> <b-button @click="openModal(2)">打开2</b-button> <b-modal v-model="modal_states[3]">模态框3</b-modal> <b-button @click="openModal(3)">打开3</b-button>
data: { modal_states: {}, }, methods: { openModal(index){ this.modal_states = {[index.toString()]:true} } },
https://codepen.io/timfranklin/pen/abWEwLy?editors=1111