请老师看一下这个报错
来源:2-5 编程练习
慕瓜5023859
2020-09-03 06:48:35
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>demo1</title>
<script type="text/javascript" src="vue.js"></script>
<style>
</style>
</head>
<body>
<div id="app">
<input type="text" v-model="inputValue">
<button v-on:click="BtnClick">提交</button>
<ul>
<li v-for="item in listArray">{{item}}</li>
</ul>
</div>
<script>
let vueApp = new Vue({
el: '#app',
data: {
listArray: [],
inputValue: ''
},
method: {
BtnClick: function() {
this.list.push(this.inputValue);
this.inputValue = '';
}
}
})
</script>
</body>
</html>
报错:
vue.js:634 [Vue warn]: Property or method "BtnClick" 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.
(found in <Root>)
warn @ vue.js:634
vue.js:634 [Vue warn]: Invalid handler for event "click": got undefined
(found in <Root>)
1回答
同学你好,问题解答如下:
该报错是因为“methods”单词写错了,少写了一个“s”,所以报了“BtnClick" is not defined这个错误;另外,往数组listArray追加元素时,变量名要对应,不是“list”,综上,修改如下:

如果我的回答帮到了你,欢迎采纳,祝学习愉快!
相似问题