首页 > 解决方案 > Vue js,属性或方法“showExplaination”未在实例上定义,但在渲染期间引用

问题描述

我正在尝试使用 Vue js 做一个网站,但我遇到了 @click 问题,找不到函数 showExplaination()。

我有以下错误: [Vue 警告]:属性或方法“showExplaination”未在实例上定义,但在渲染期间被引用。通过初始化该属性,确保该属性是反应性的,无论是在数据选项中,还是对于基于类的组件。

<div class="vue">

    <button class="btn btn-danger" @click="showExplaination">
            Show explaination                    
    </button>
    
    <div v-show="explaination">Explaination</div>
</div>

这是javascript代码

var app = new Vue({
    el: '.vue',
    data: {
        explaination: false
    },
    method: {
        showExplaination: function() {
            this.explaination = !this.explaination;
        }
    }
});

谢谢你的帮助

标签: htmlvue.js

解决方案


推荐阅读