我如何在v-for循环内调用模式组件?

问题描述 投票:0回答:1

我使用vuetify https://vuetifyjs.com/en/

我的父组件是这样的:

<template>
  <v-container>
    ...
        <v-col
        v-for="(item, i) in items"
        :key="i"
        >
        <v-card
        >
            <v-app-bar dark color="grey">
            <v-toolbar-title>Weekly Schedule : {{item.name}}</v-toolbar-title>
            <div class="flex-grow-1"></div>
            <modal-datepicker :schedule="item"  />
            </v-app-bar>
        </v-col>
    ...
  </v-container>
</template>

<script>
import { mapState } from "vuex";
import modalDatepicker from "../views/modalDatepicker";
export default {
  components: {modalDatepicker},
};
</script>

我的子组件是这样的:

<template>
    <v-dialog
        :ref="dialog"
        v-model="modal"
        :return-value.sync="date"
    >
        <template v-slot:activator="{ on }">
            <v-btn color="success" dark v-on="on">Show datepicker</v-btn>
        </template>
        <v-row justify="center">
            <v-date-picker v-model="date" scrollable>
                <div class="flex-grow-1"></div>
                <v-btn text color="primary" @click="modal = false">Cancel</v-btn>
                <v-btn text color="primary">OK</v-btn>
            </v-date-picker>
        </v-row> 
    </v-dialog>
</template>

<script>
import { mapState } from "vuex";
import modalDatepicker from "../views/modalDatepicker";
export default {
  components: {modalDatepicker},
  props: ['schedule'],
  data: () => ({
    date: new Date().toISOString().substr(0, 10),
    modal: false,
  }),
  mounted() {
    console.log(this.schedule)
  },
};
</script>

上面的代码有效,但效率低下。因为每次循环时,它都会调用模式对话框。我希望仅当用户单击“显示日期选择器”按钮时才调用模式

我该怎么做?

我使用vuetify https://vuetifyjs.com/en/我的父组件是这样的:

vue.js modal-dialog vue-component vuex vuetify.js
1个回答
0
投票
我在手机上致歉。您是否考虑过将模态包含在循环之外的父组件中?
© www.soinside.com 2019 - 2024. All rights reserved.