Gijo Varghese
Gijo Varghese

Reputation: 11780

Reload Components when change in Props in VueJS

I'm using the following code to show a component which passes a value 'category'. The category changes based on user interactions. However, once a component is loaded, its data is not changed according to the change of props.

<button @click="selected='new'">Change</button>
<popup :category="selected"></popup>

data() {
    return {
      selected: 'test'
    }
  }

Upvotes: 3

Views: 14870

Answers (1)

Saurabh
Saurabh

Reputation: 73589

You will have to put a watcher on category in popup component, like following:

watch: {
  category: function(newVal){
    this.selected = newVal   // or this.openPopup(newVal) is this suits
  }
}

Upvotes: 9

Related Questions