我需要将VueJS变量传递给VueJs函数而不提交页面。由于某种原因,表单在将变量传递给函数后仍在提交。
HTML
<div class="list-group-item" v-for="event in events">
<form method="POST" v-on:submit.prevent="deleteEvent('@{{ event.id }}')")>
<b><h1>@{{ event.name }}</h1></b>
<hr>
<small>@{{ event.description }}</small>
<hr>
<b>@{{ event.date }}</b>
<hr>
<button class="btn btn-danger form-control">Delete</button>
</form>
</div>
的JavaScript
new Vue({
el: '#app',
data: {
newEvent: {
name: '',
description: '',
date: ''
}
},
ready: function(){
this.retrieveEvents();
},
methods: {
retrieveEvents: function(){
this.$http.get('/retrieveEvents', function(response){
this.$set('events', response);
});
},
addEvent: function(e){
e.preventDefault();
var event = this.newEvent;
this.$http.post('/addEvent', event, function(){
this.newEvent = {name: '', description: '', date: ''};
});
this.retrieveEvents();
},
deleteEvent: function(id){
e.preventDefault();
console.log(id);
}
}
});
我不明白为什么它一直提交表单而不是将变量传递给VuejJS,其他一切都很完美。
答案 0 :(得分:1)
您无需在绑定语法中进行插值,您可以直接访问属性:
DataTrigger