The function vm.handleClick does not exist in Vue.js

I have been trying to implement toggle buttons from the argon template and came across an issue. Here is the code snippet:

<template>
  <div class="option">
      <div>Show value
          <label class="custom-toggle">
          <input type="checkbox" @click="handleClick($event)">
          <span class="custom-toggle-slider rounded-circle"></span>
          </label>
          <div v-if="viewCheck"> 
           <div>Name </div>
           <div>Surname</div>
          </div>
       </div>
  </div>
</template>

<script>
export default {
  name: 'Options',
  data: function() {
    return {
      viewCheck:false
    }
  },
  handleClick: function(event) {
      console.log(event)
      this.viewCheck = true
  }
}
</script>

However, upon clicking on the toggle button, I encountered the following error message:

TypeError: _vm.handleClick is not a function
at click (eval at ./node_modules/vue-loader/lib/template-compiler/index.js?{"id":"data-v-6f2958af","hasScoped":false,"transformToRequire":{"video":["src","poster"],"source":"src","img":"src","image":"xlink:href"},"buble":{"transforms":{}}}!./node_modules/vue-loader/lib/selector.js?type=template&index=0!./src/views/Option.vue
(app.js:7731), :22:34)
at invokeWithErrorHandling (vue.esm.js?efeb:1863)
at HTMLInputElement.invoker (vue.esm.js?efeb:2188)
at HTMLInputElement.original._wrapper (vue.esm.js?efeb:7559)

Answer №1

Make sure to include it in the methods section.

Consider using this approach:

export default {
  name: 'Settings',
  data: function() {
    return {
      showView: false
    }
  },
  methods: {
    handleClick: function(event) {
      console.log(event)
      this.showView = true
    }
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Handling Removal of Selected Option in React Material-UI Autocomplete Single Selection

I am currently using material UI autocomplete to create a single-select dropdown. However, I have encountered an issue wherein the onChange event does not get triggered when I click the close button on the right side of the input. This prevents my state fr ...

Utilizing an Immediate-Invoked Function Expression (IIFE) for jQuery in JavaScript

I'm looking at this code snippet that I believe is an Immediately Invoked Function Expression (IIFE). But, I'm confused about the role of (jQuery) and ($). I understand that it involves passing a reference to jQuery into the IIFE, but can someone ...

The JSON output from the gapi (Google Analytics) array in PHP is not displaying any values

I've been utilizing the gapi class within a CodeIgniter website. The implementation I'm using is based on this resource, which returns an array that functions perfectly. To pass this array to my JavaScript, I've been attempting the following ...

Chaining Promise Rejections in AngularJS

Creating chained promises is a task I need to tackle: var deferred = $q.defer(); $timeout(function() { deferred.reject({result: 'errror'}); }, 3000); deferred.promise.then(angular.noop, function errorHandler(result) { //additional action ...

Loop through each item in the JSON object

After making an ajax call, I receive a json object in the success callback with the following structure: {test 1: Array(2), test 2: Array(3), test 3: Array(2)} The arrays inside each key have elements that look like this: 0: {IdProduct: "1", ProductName ...

Understanding Vue.js - encountering the error message "property or method is not defined"

Recently, I've come across an issue that seems to be common among many people, but for some reason, I am unable to find a solution despite looking at similar questions. The problem arises when I use a v-for in a Vue Component and the array value cons ...

What is the most effective way to include JavaScript code in a PDF file?

What is the process for integrating JavaScript code into a PDF document? I am familiar with coding in JavaScript and would like to learn how to add it to a file in order to perform tasks such as displaying the current date or using a combobox. ...

PayPal Integration with React for Seamless Checkout Experience

I established a small and uncomplicated online store featuring a PayPal checkout system, and it is functioning adequately. Now, I am looking to include detailed information about the purchased products in the transaction history of my PayPal account. This ...

Setting the title attribute for option elements in a select element that is bound to a model using AngularJs

I'm currently working on an HTML select element that is connected to an ng-model. Here's what the setup looks like: <select data-ng-model="accountType" data-ng-options="at.name for at in accountTypes"></select> This is how my accou ...

Problem with the property `className` not adding correctly on `$scope.eventSource`

Currently, I am utilizing the AngularJS directive to integrate the Arshaw FullCalendar. However, I am encountering an issue where the className specified in $scope.eventSource is not appearing on the event object. Here is a snippet of my code: $scope.even ...

Every time I rotate my div, its position changes and it never goes back to

Trying to create an eye test by rotating the letter "E" when a directional button is clicked. However, facing an issue where the "E" changes position after the initial click instead of staying in place. Here is a GIF showcasing the problem: https://i.stac ...

Display all months vertically with Bootstrap-Year-Calendar instead of horizontally

I recently integrated the Bootstrap-Year-Calendar plug-in into my project, but it seems to be displaying vertically. I'm not sure if this issue is related to my scripts or links. I attempted to change the versions of both jQuery and Bootstrap, but the ...

The calculator is generating console logs, but there is no output appearing on the display

I'm currently working on a calculator project using JavaScript and jQuery. I am facing an issue where the numbers are not displaying on the screen when I press the buttons, but they do show up in the console log without any errors. I would appreciate ...

The Next.js build version encounters an issue with 'auth' property being undefined and causes a failure

Our team has been happily working on a Next.js based website for the past few months. Everything was running smoothly without any major issues until yesterday when we encountered an error on the production version while using router.push: Cannot read prope ...

Unlock the potential of your Vue component by accessing and activating the dynamic :class and :style alterations

Several moons ago, I crafted a Vue wrapper for the Select2 component. This elegant wrapper skillfully wields the bind:class and bind:style attributes, dutifully relaying them to the Select2 library in the following manner: this.$vnode.data.staticClass // b ...

Transferring data from PHP to AJAX and then injecting it into an SQL query

I've been attempting to pass a datepicker variable into an onclick ajax function, which then sends it to another ajax method that passes the variable to an SQL query. The result of the query is then passed back into the ajax function to generate a cha ...

Extract the text from a Spotify mobile application

One of the features in my application is generating a link based on the currently playing song. To make it user-friendly, I want to implement a button that will copy the generated link to the clipboard when clicked. I've explored options like zerocli ...

The aoColumns functionality in datatables seems to be malfunctioning

Attached is the application picture, where the column ORDER ID is not showing and instead a PLUS sign is displayed. This causes all columns to shift one position to the right. ajax Every time I run the application, it displays the following error message: ...

React 16 Component Size Attribute (size="test") is being eliminated

Is anyone else encountering a similar issue where the size attribute of a React component is getting removed? For example, `ReactDOM.render( <h1 size="hello">Hello, world!</h1>, document.getElementById("root") );` You ...

Access the reset button on a dynamic image using the document.getElementById method

I'm still new to coding in JavaScript and I have a question. In my class, I was required to assign four buttons to four different JavaScript commands. I managed to get three of them working successfully, but the last one seems to be giving me trouble. ...