Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vue method showing as undefined

I’m trying to trigger an event on button click but this code which I expect to work isn’t working.

I thought it was because I had no value in the data section initially so added data to allow the component to be reactive. That didn’t do anything so I have no idea what to try next.

Code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<template>
  <div>
    <button @click="liveChatTrigger">{{ text }}</button>
  </div>
</template>

<script>
export default {
  name: "LiveChatButton",
  method: {
    liveChatTrigger() {
      alert('trigger')
    }
  },
  data() {
    return {
      text: 'Start a live chat now'
    }
  }
}
</script>

Error

[Vue warn]: Property or method "liveChatTrigger" 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. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

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

(found in <Root>)

>Solution :

You have defined the function in the method property. It should be methods.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading