<form v-on:submit="addCustomer">
<button type="submit" class="btn btn-primary">添加</button>
</form>
addCustomer(e){
//console.log(12221);
if(!this.coustomer.name || !this.customer.phone || !this.coustomer.email){
this.alert="請輸入電話郵箱和姓名!!!";
}else{
let newCustomer={
name:this.coustomer.name,
....
}
e.preventDefault();
}
}
}
怎么叫无法使用,全部删除掉,就保留console.log(12221);,有输出么
你这是啥模板的语法,你用浏览器打开查看一下form的属性是否正常,正常应该是onsubmit="addCustomer()"
需要有(),当然()中可以有参数,目测可以是this
你看看网页源码是否正常!
再者你的form是会提交跳转的,你如果想阻止的话,应该用onsubmit="return addCustomer(this);"
不然可能直接跳转了,如果没有像alert、prompt之类的窗口级干预程序的话!