我需要在不提交页面的情况下将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,其他所有东西都可以正常工作。

最佳答案

您不需要插值绑定语法,可以直接访问属性:

<form method="POST" v-on:submit.prevent="deleteEvent(event.id)">

10-04 16:31