用户单击编辑后,我正在初始化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传递给模态。

谁能建议我如何将变量传递给模态?

最佳答案

您可以在@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>

关于javascript - 将变量传递到Vue js模式组件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56037171/

10-10 18:41