samedi 16 février 2019

Data not refreshing from child component to parent

I have a child component that I add in links. Once completed I call the parent component to fetch the new links. I know it's hitting that function because I've put console.logs in that function.

My links in the v-for aren't updating. They are only updating when I reload the page with the new entry. Upon submit, I want my child component to notify/call the parents fetchLinks function to update all the links on the screen (Which its not updating, unless I refresh page)

This is on the form success function from Child AddLinksComponent

// Get the new updated subscriptions 
this.$parent.fetchLinks()

Parent Component

<div class="card card-body" v-for="link in links" v-bind:key="link.id">
   <h2></h2>
</div>

      <add-links></add-links>


export default {
    data() {
        return {
            links: [],
        }
    },
    components: {
       'add-links': AddLinksComponent,
    },
    methods: {
        fetchLinks() {

            fetch('/links/')
            .then(res => res.json())
            .then(res => {
                this.links = res.data
            }).catch(err => {
                console.log('Error', err)
            });
        }
    },
    created() {
        this.fetchLinks();
    },
    mounted() {

    }
}



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2V5OHaD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire