I am using Laravel and trying to learn Vue.js. I have a delete request that works correctly and removes an object from the database. The problem is that it is not removed from the DOM after a successful deletion. I use the $remove method and pass it the full object, so I know that I am missing something.
As a side note, I have main.js as an entry point with PersonTable.vue as a component. PersonTable.vue contains the template and script for this template.
Here is my view on Laravel:
<div id="app"> <person-table list="{{ $persons }}"> </person-table> </div>
And here is my `PersonTable.vue:
<template id="persons-template"> <div class="container"> <div class="row"> <div class="col-sm-12"> <h1>Persons List</h1> <table class="table table-hover table-striped"> <thead> <tr> <td>First Name</td> <td>Last Name</td> <td>Email</td> <td>Gender</td> </tr> </thead> <tbody> <tr v-for="person in list"> <td>{{person.first_name }}</td> <td>{{person.last_name }}</td> <td>{{person.email }}</td> <td>{{person.gender }}</td> <td><span @click="deletePerson(person)">X</span> </td> </tr> </tbody> </table> </div> </div> </div> </template> <script> export default { template: '#persons-template', props: ['list'], methods: { deletePerson: function(person) { this.$http.delete('/person/' + person.id).then( function(response) { this.persons.$remove(person); } ); } }, created: function() { this.persons = JSON.parse(this.list); } }; </script>
And my main.js entry main.js :
var Vue = require('vue'); Vue.use(require('vue-resource')); var Token = document.querySelector('meta[name="_token"]').getAttribute('content'); Vue.http.headers.common['X-CSRF-TOKEN'] = Token; import PersonTable from './components/PersonTable.vue'; new Vue({ el: '#app', components: { PersonTable }, })
dericcain
source share