0

i want to create a delete function with vue js in my laravel app.

here what i try

my .vue code

<tr v-for="(artist, index) in artists.data">
    <td>{{ artist.artist_name }}</td>
    <td>{{ artist.gender }}</td>
    <td>{{ artist.created_at }}</td>
    <td>{{ artist.updated_at }}</td>
    <td>Edit | <a href="javascript:;" v-on:click="deleteUser(artist.id, index)">Delete</a></td>

my variable

data() {
    return {
        term:'',
        disabled: 0,
        artists: [],
        results: [],
        loading: false,
        noResults: false,
        SearchDiv: false,
        IndexDiv: true
    }
},

my delete method

deleteUser(id, index) {
    axios.delete('/api/artist/'+id)
    .then(resp => {
        this.artists.splice(index, 1);
    })
    .catch(error => {
        console.log(error);
    })
}

error i get

TypeError: _this4.artists.splice is not a function

code above can delete data from database but not remove data from array result.

2
  • I think being on Vue is easier you reload the artists array. Commented Jan 3, 2019 at 8:42
  • how to do it..? Commented Jan 3, 2019 at 8:43

1 Answer 1

2

You are splicing data to its mother array.

Try this.

this.artists.data.splice(index, 1);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.