Error in Vuejs: Property '_withTask' is undefined

I am attempting to dynamically add new HTML elements to my div upon button click, using v-for. However, I encounter an issue where the element (article) is added successfully on the first click, but subsequent clicks result in an error.

vue.js?3de6:1743 TypeError: Cannot read property '_withTask' of undefined
at remove$2 (eval at (app.js:561), :7078:13)
at updateListeners (eval at (app.js:561), :2067:7)
at Array.updateDOMListeners (eval at (app.js:561),:7091:3)
at patchVnode (eval at (app.js:561), :5918:62)
at updateChildren (eval at (app.js:561), :5809:9)
at patchVnode (eval at (app.js:561), :5923:29)
at updateChildren (eval at (app.js:561), :5809:9)
at patchVnode (eval at (app.js:561), :5923:29)
at updateChildren (eval at (app.js:561), :5809:9)
at patchVnode (eval at (app.js:561), :5923:29)

HTML CODE :

<article v-for="item in range">
    <span>
        {{item[0]}} - {{item[1]}}
    </span>
    <span>
        <button  class="btn btn-theme btn-default btn-xs pull-left"  @click="deleteItem" ><i class="fa fa-times inline"></i></button>
    </span>
</article>

JS :

data() {
    return {
        majornew:this.major,
        certificate:this.cert,
        range:[], 
        item:[],
    };
},

methods: {
    addmajorcert(majortext,certext) {
        this.item = [majortext,certext];
        this.range.push(this.item);
        console.log(majortext,certext);
    },
},

Updated :There are two select boxes where values get sent

<v-select v-model="selectedmajor" label="major_text" id="major" name="majornew" :options="majornew" >
</v-select> 
<v-select v-model="selectedcert" :options="certificate" label="lc_text" id="cert" v-on:click="certificate"></v-select> 

<button v-on:click="addmajorcert(selectedmajor,selectedcert)">
    +
</button>

The select box returns an object like :

{ "major_id": 2, "major_text": "industrial", "number_of_used": 1 }

Upon using a console.log, I can observe the values being passed successfully.

Answer №1

Encountered the same issue due to using an event that was not defined in the script. Here's an example illustrating the problem:

<template>
 <div>
  <button @click="deleteItem"></button>
 </div>
</template>

In this case, the deleteItem method is being used, but there is no corresponding function defined within the methods object of the script which results in an error with _withTask. This could potentially be a common mistake for others as well.

<script>
 export default {
  methods: {
   // No function named deleteItem
  }
 }
</script>

To put it simply, the error occurs when an event function remains undefined. :)

Answer №3

<article v-for="item in options">

Your data includes both options and item, but you are looping over options and naming each iteration item. This could potentially cause issues, consider renaming your item in the v-for loop:

<article v-for="selection in options">

Additionally, it is recommended to use a unique key when using v-for, such as:

<article v-for="selection in options" :key="selection.id">

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

Eliminating specific classes targeted by a jQuery attribute selector within the outcome of another jQuery attribute selector

I am facing a simple issue where I need to target all classes that end with a specific string on elements within a class ending with another specific string, and then remove those targeted classes. While the following code is close to what I want, it does ...

Ways to append multiple values to an object ID in mongoDB at a later time

I have a pre-existing object ID in my MongoDB database, and I am looking to add more values inside it in the future. Here is an example of my current MongoDB structure: [{ label: 'colors', options: [ { label: 'Bl ...

What is the best way to create a function that will return a Promise within an Express Route?

I am working with a business level database module named "db_location" that utilizes the node-fetch module to retrieve data from a remote server through REST API. **db_location.js** DB LOGIC const p_conf = require('../parse_config'); const db_ ...

Switching the form element from an input to a select option results in the JavaScript function malfunction

My form elements are functioning perfectly: <input id="addressinput1" style="width:20%" value="Enter Address"/> <input id="showaddress1" type="button" value="Show Tech Home" style="width:10%"/> The code above successfully triggers the followi ...

Error: The module 'semver' could not be located during the npm installation process

Having trouble with npm install in the NodeJS command prompt. When I run npm install, I encounter the following errors: module.js:339 throw err; ^ Error: Cannot find module 'semver' at Function.Module._resolveFilename (module.js:337: ...

Prevent the parent component's ripple effect from being activated by the child component

If I have a simple code snippet like the following: <ListItem button={true} > <Typography variant='caption' color='primary'> {value} </Typography> <Button onClick={foo} > Button ...

Guide to executing a chain of parallel API calls with changing parameters using nodejs

I am working on a project that involves making multiple API calls while changing a single parameter value in the URL based on values stored in an array. Currently, I have about 30-40 values in the array and I am using NodeJS and Express for this task. Belo ...

Performing a targeted ajax request to retrieve a set of data

Is it possible to create a collection using a specific ajax call instead of fetching by its URL? Normally, when fetching by a collection, the URL in the collection is used. However, I need to retrieve results from an ajax call rather than the URL. $.ajax( ...

"Can someone guide me on where to place the JavaScript code within this Bootstrap snippet when working with CakePHP

I'm currently delving into CakePHP and am eager to incorporate this Bootstrap code snippet from onto my website. I've successfully added the HTML to the .ctp file in the Pages directory and styled it with custom.less, but I hit a roadblock when ...

jQuery - Uh-oh! Looks like there is a syntax error and the

I encountered an issue with my fiddle where I am getting an error message. Any suggestions on how to effectively handle decimals and spaces within the code, specifically when using .split and join() functions, without causing an unrecognized expression e ...

Using v-model in Vue with jQuery integration

I wrote a jQuery code that is executed when the mounted hook runs mounted() { this.$progress.finish(); var geocoder = new google.maps.Geocoder(); var marker = null; var map = null; function initialize() { var $latitude = document.getEl ...

Navigating shadow dom elements in HTML with Selenium WebDriver

public WebElement retrieveShadowRootElement(WebElement element) { WebElement shadowRoot = (WebElement) ((JavascriptExecutor)driver) .executeScript("return arguments[0].shadowRoot", element); return shadowRoot; } WebElement rootElement= dri ...

What is the best way to retrieve a specific value from a JSON file using a numerical identifier?

Imagine a scenario where there is a JSON file structured like this: { "data": [ { "id": "1", "name": "name1" }, { "id": "2", "name": "name2" } ] } If you know the ...

Issue with the scope causing global variable not to update when button is pressed

I am facing an issue with a declared variable and jQuery code that is supposed to store a form's value as the value of that variable when a button is clicked, and then execute a function. var verb = ""; $( "#submit" ).click(function() { verb = $(& ...

Error: Attempting to access 'title' property of undefined object leads to Uncaught TypeError

I am attempting to extract content from a Google Blogger Feed that can be found at this link. I am using JavaScript code from here. When inspecting the elements, I encountered a specific red warning message: Uncaught TypeError: Cannot read property ' ...

What are some ways to create a versatile wrapper?

I'm currently grappling with an issue involving my Formik fields. I need to utilize FastFields in certain scenarios and Fields in others within my FormikControl, a class designed for constructing formik inputs. The challenge lies in being able to swit ...

Performing addition calculations with arrays in JavaScript

Given an array, the task is to find the total sum of all elements in the array. let numbers = [1, 3, 2, 0]; console.log(numbers.sum()); ==> 6 I need assistance on how to implement the sum function. Can you help me? ...

Utilizing query parameters as variables in rewrites with Next.js

My goal is to use Next JS to redirect requests from /home?id=123qwert to the new path of /home/123qwert. I'm struggling with extracting the query parameter from the source and using it in the destination. This is what I have attempted so far: as ...

What is the best way to incorporate Javascript and Jquery into a Rails 4.2.4 application running on Ruby 2.2.3?

Currently, I am working on an app using Ruby on Rails with the specified versions of Rails and Ruby. My main goal is to integrate JavaScript/ jQuery into my mindmap index views in order to dynamically add information to the page without requiring a full p ...

Unable to retrieve a particular file from S3 while utilizing Strongloop

While I am able to upload, delete, and list folders from an Amazon S3 container using Strongloop, I am facing difficulties retrieving a specific file. This is my code: $scope.getS3Files = function(myfolderName){ //need to fetch all zip files in myfolderA ...