问题描述
每当我尝试单击该按钮时,它都不会添加任何记录。但是当我在输入字段@keyup.enter="addusers"
上输入内容时,按回车键便可以使用。我希望它与“添加”按钮一起使用。有人可以给我建议吗。
.row
input(type='text',v-model='newUser')
input(type='text',v-model='newMail')
button.btn.btn-primary(type='button' @onclick="addUsers") Add
.col-lg-12.text-left(v-for="user in users")
p {{ user.name}}- {{user.email}}
addUsers() {
axios.post('https://jsonplaceholder.typicode.com/users',{
name: this.newUser,email: this.newMail
})
.then(({data}) => {
this.users.push(data);
});
解决方法
应将点击事件写为@click
而不是@onclick
button.btn.btn-primary(type='button' @click="addUsers") Add