javascript - 将变量传递给 Vue js 模态组件
问题描述
在用户单击编辑后,我正在初始化Vue js 模态。
这是模态元素:
<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
给模态。
谁能建议我如何将变量传递给模态?
解决方案
@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>
推荐阅读
- php - 在对象 foreach 循环中将结果限制为一个,in_array 不起作用
- ruby-on-rails - Rails:如何用 0 计算模型
- apache-spark-sql - 保存到 cassandra 时有时会出现 NullPointerException
- javascript - 如何在角度 6 中添加计数器?
- c++ - 错误:在将值分配给指针时,不应忽略 void 值
- git - 尝试克隆私有 git 存储库,不要求提供 uid/pwd,获取“核心”文件
- winapi - VariantClear 发布 VT_DISPATCH -vs- MSDN 文档
- typescript - 如何在打字稿中定义 Option Partial?
- php - 通过自定义字段获取帖子顺序
- java - 在多线程中使用 Yield