开发者问题收集

[Vue 警告]:事件“click”的处理程序无效:未定义

2019-06-06
12148

我使用 vue js 作为前端框架,并在按钮上定义了 @click 事件。但是,当我单击它时,出现以下错误:-

[Vue warn]: Property or method "getArea" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

[Vue warn]: Invalid handler for event "click": got undefined

found in

---> <ElButton> at packages/button/src/button.vue
       <ElCard> at packages/card/src/main.vue
         <ElCol>
           <ElRow>
             <ElCol>
               <ElRow>
                 <ElHeader> at packages/header/src/main.vue
                   <ElContainer> at packages/container/src/main.vue
                     <ProgressBar> at src/views/Map/components/ProgressBar.vue

我在以下链接中发现了类似的问题:- VueJS - 事件“click”的处理程序无效:未定义

但似乎没有解决问题

ProgressBar.vue

<template>
  <el-col class="progress-bar-icon" :span="6">
    <span class="step-text">Step-2<br/></span>
    <el-button id="two" class="icon" icon="el-icon-location-outline" circle></el-button>
      <el-card v-if="ifLocation" class="dialog-box-card">
        <h4 class="heading">Pin Down Your Roof On The Map</h4>
        <el-button type="primary" round @click="getArea">Next <i class="el-icon-arrow-right"></i>
        </el-button>
      </el-card>
  </el-col>
</template>

<script>
export default {
    name:'progress-bar',
    data(){
        return {   
            ifLocation:true,
            ifArea:false,
        }
    },
    method:{
        getArea(){
            this.ifLocation=false
            this.ifArea=true
        }
    }
};
</script>

index.vue

<template>
  <div>
    <progress-bar></progress-bar>
  </div>
</template>

<script>
import ProgressBar from './components/ProgressBar';

export default {
  name:'index',
  components:{
    'progress-bar':ProgressBar,
  },

};
</script>
2个回答

请将“method”更改为“methods”

如下所示:

methods:{
        getArea(){
            this.ifLocation=false
            this.ifArea=true
        }
    }
Midhun
2019-06-06

我终于找到了。错误发生是因为我们调用了 methods 中未找到的函数。例如,我们在 div 中使用了“increase”函数,但我们没有在 methods 中定义此函数。当我们将此函数添加到 methods 中时,问题就消失了。

doğukan
2019-11-03