【问题标题】:Vuejs component click event not workingVuejs组件单击事件不起作用
【发布时间】:2018-11-11 19:00:33
【问题描述】:

我正在使用 Vuejs - Vuikit 组件并具有以下设置:

<template>
    <div class="uk-scope">
        <vk-modal :show="isShow" v-if="config">
          <vk-modal-close @click="alert('hello!')" large></vk-modal-close>
          <vk-notification :messages.sync="messages"></vk-notification>
            <app-breadcrumb :current-view="currentView" />
            <!-- render the currently active component/page here -->
            <component v-bind:is="currentView"/>
        </vk-modal>
    </div>
</template>

我的问题是,关闭模式不会触发 @click 函数。

父组件确实会发出一个事件,但我更愿意直接从关闭按钮触发。

我曾尝试使用@click.native="someFunction()",但这没有帮助!

【问题讨论】:

  • 控制台是否出现任何错误?如果我理解正确,alert('hello!') 应该在对话框关闭时显示?如果是这种情况,可能是当它关闭时,您会丢失对该方法的引用,因此它永远不会发生

标签: javascript vue.js vuejs2 vuikit


【解决方案1】:

嘿,我以前没有使用过 vuikit,但是从他们的文档中他们展示了这是如何关闭模式的。我也会删除那个 v-if="config" 因为这可能会让 Vue 感到困惑

<template>
    <div class="uk-scope">
        <vk-modal :show.sync="isShow">
          <vk-modal-close @click="isShow = false" large></vk-modal-close>
          <vk-notification :messages.sync="messages"></vk-notification>
            <app-breadcrumb :current-view="currentView" />
            <!-- render the currently active component/page here -->
            <component v-bind:is="currentView"/>
        </vk-modal>
    </div>
</template>

【讨论】:

    【解决方案2】:

    您是否尝试过使用@click.native="someFunction",注意这里没有()

    【讨论】:

      猜你喜欢
      • 2018-06-15
      • 2018-03-06
      • 2018-09-05
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多