user3711357
user3711357

Reputation: 1635

How to update prop value when its set in Component

In Vue component, when set the 'PROPS' immediately, needs to update the collection to include additional property.

Component is:

Vue.component('blog-post', {
  props: ['dataArray']   //needs to update this value when it sets.
...
})

Upvotes: 0

Views: 1308

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

You could change it in the parent by emmiting the value from the child component like :

   Vue.component('blog-post', {
        props: ['dataArray']   //needs to update this value when it sets.
      ,
     methods:{
     update(val){
        this.$emit('updatedata',val)
     } 
     }
  })

and in the parent component use it as follow :

    <blog-post @updatedata="updatedataArray"><blog-post>

    ...
      methods:{
         updatedataArray(val){
         //update your data array   
         }
      }

Upvotes: 1

Related Questions