用户点击编辑后,我正在初始化Vue js modal。
这是模式元素:
<modal name="edit-time">
<div class="row col"">
<div class="time">
<div class="form-row mb-3">
<div class="col-4">
<label for="time">Time</label>
</div>
<div class="col-8">
<input type="time" v-model="time" id="time" class="form-control">
</div>
</div>
</div>
</div>
</modal>
这是我打开模态的地方
<button @click="showEditModal()" type="button">Edit</button>
这是JS部分
<script>
export default {
name: 'demo',
components: {
},
data () {
},
created () {
},
computed: {
},
methods: {
showEditModal () {
time = "15:15";
this.$modal.show('edit-time', { time: time });
},
hideModal () {
this.$modal.hide('edit-time');
}
},
}
</script>
我试图将变量time
传递给模态的方法。
有人可以建议如何将变量传递给模式吗?
答案 0 :(得分:2)
您可以在@beforeOpen
事件中将道具绑定到本地数据
<template>
<modal name="edit-time" @before-open="beforeOpen">
<div class="row col">
<div class="time">
<div class="form-row mb-3">
<div class="col-4">
<label for="time">Time</label>
</div>
<div class="col-8">
<input type="time"
v-model="localTime"
id="time"
class="form-control">
</div>
</div>
</div>
</div>
</modal>
</template>
<script>
export default {
data() {
return {
localTime: null
}
},
methods: {
beforeOpen(event) {
this.localTime = event.params.time
}
}
}
</script>