S
S
semki0962019-04-30 17:13:41
Vue.js
semki096, 2019-04-30 17:13:41

How to make reactivity when deleting an entry in vue.js using my example?

I display images in a loop

<tr v-for="img in image">
    <td>{{ img }}</td>
    <td> <button v-on:click="removeImage(id)">Remove image</button></td>
</tr>

The button removes the image from the database with Ajax.
removeImage(id) {
                        axios.post('/img/delete/' + id).then(function(){
                          console.log('SUCCESS!!');
                        })
                        .catch(function(){
                          console.log('FAILURE!!');
                        });
                    },

Question - how to make the picture on the page reactively disappear? I mean using vue js if possible. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pantagruel964, 2019-04-30
@semki096

<tr v-for="(img, n) in image">
    <td>{{ img }}</td>
    <td> <button v-on:click="removeImage(n)">Remove image</button></td>
</tr>

...
.then(response => {
     this.image.splice(n, 1);
})
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question