Reputation: 3060
I have a parent component that pass a config object as props
to its child.
I wish to add set reactive entries to this object, for example:
created() {
this.config.page = this.config.page || 1
}
So from this moment, the changes for page
will be reactive.
Is it possible?
A not successful attempt:
beforeCreate() {
if(!this.$options.propsData.config.page){
Vue.set(this.$options.propsData.config, 'page', 1)
}
}
Upvotes: 4
Views: 2554
Reputation: 33917
Change it from beforeCreated
to created
. This should work for you I think:
create() {
if(!this.$options.propsData.config.page){
Vue.set(this.$options.propsData.config, 'page', 1)
}else{
this.config.page = 1;
}
}
Upvotes: 3