我尝试在按下按钮后使用 v-for
向我的 div 添加新的 html。
但是在我按下按钮后我得到了这个错误并且元素(文章)被添加到 div 一次但之后它就不再起作用了。
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 代码:
<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);
},
},
更新:有两个用于发送值的选择框
<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>
选择框返回一个对象,如:
{ "major_id": 2, "major_text": "industrial", "number_of_used": 1 }
当我执行 console.log
时,我可以看到正在传递的值。
最佳答案
我有同样的问题,那是因为我正在使用一个事件,但它没有在脚本中定义这里是示例问题:
<template>
<div>
<button @click="deleteItem"></button>
</div>
</template>
所以你可以看到我正在使用 deleteItem
方法,但在方法对象下面的脚本中我没有使用该名称的函数。这导致我错误 _withTask。我认为这可以由其他人完成。
<script>
export default {
methods: {
// No function with name deleteItem
}
}
</script>
基本上错误是在简单语言中未定义事件函数时引起的:)
关于javascript - Vuejs - 无法读取未定义的属性 '_withTask',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52425393/