【问题标题】:Unable to close a modal in vue via v-model无法通过 v-model 在 vue 中关闭模态
【发布时间】:2022-01-07 16:50:13
【问题描述】:

当我按下显示Close 的按钮时,我从控制台收到以下错误:

"Error: Cannot find module './undefined'"

found in

---> <WhatsNew> at src/components/WhatsNew.vue 

下面是WhatsNew.vue

<template>
  <u-modal v-model="modalActive">
      ......
      ......
      <div class="whats-new-options">
        <div id="whats-new-checkbox">
          <u-checkbox v-model="whatsNewStatusInactive" label="Don't show again"/>
        </div>
        <div id="whats-new-next-button">
          <u-button id="whats-new-close-btns" full color="secondary" @click="nextNew">{{notViewedAll ? 'Next' : 'Close' }}</u-button>
        </div>
      </div>
    </div>
  </u-modal>
  
</template>
<script>
  import { mapGetters, mapMutations } from "vuex";
  export default {
    data() {
      return {
        modalActive: false,
        notViewedAll: true,
        newFeaturesOnUsedCount: 3,
        current: 0,
      }
    },
    methods: {
      ...mapMutations("client", ["updateWhatsNewStatus"]),
      nextNew() {
        if (this.current <= this.newFeaturesOnUsedCount -1 ){
          this.current += 1
        }
        if (this.current >= this.newFeaturesOnUsedCount && !this.notViewedAll) {
          this.modalActive = false
        }
        
        if (this.current >= this.newFeaturesOnUsedCount - 1) {
          this.notViewedAll = false
        }
        
      }
    }

我不确定是什么导致了错误,我已通过更改使用创可贴解决方案修复它:

<u-modal v-model="modalActive">

<u-modal v-model="modalActive" v-if="modalActive">

然而这感觉不对,我应该不需要使用v-if 来控制模态,v-modal 本身就足够了吗?但是为什么我会收到上面提到的错误?谢谢

【问题讨论】:

  • 什么是 u-modal?
  • 这是一个内部模式,但它只是从引导程序链接一个
  • 通常 v-model 不用于打开和关闭模式,因为它只是 input :value 和 @input 事件的简写包装。这个模态目前是如何打开的?用方法?还是页面默认打开?
  • 此代码(单独)有效。请发布您如何调用/打开模式。可能有其他内容不在发布内容的范围内

标签: javascript vue.js


【解决方案1】:

尝试使用 v-show 代替,您不需要使用 v-model。

&lt;u-modal  v-show="modalActive"&gt;

【讨论】:

    猜你喜欢
    • 2019-01-27
    • 1970-01-01
    • 2021-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 2020-01-23
    • 2020-10-29
    相关资源
    最近更新 更多