0👍
Instead of trying to add the props in beforeCreate
, declare props
in your mixin object:
Vue.mixin({
props: {
name: {
type: String
},
age: {
type: Number
},
gender: {
type: String
}
}
})
- [Vuejs]-VueJs how to remove global error handler for testing with vue-test-utils
- [Vuejs]-My Vue CDN code is not working, my output says {{ name }}
0👍
Like you noticed and my first comment mentioned: its about vm.$attrs
:
beforeCreate(){
this.$options.props = {propName: {}};
this.$options.propsData = this.$attrs;
}
but be aware that you need to delete those props from attrs to stay consistent with vue, e.g:
Object.keys(this.$options.props).forEach(key => this.$attrs.hasOwnProperty(key) && delete this.$attrs[key])
hope this helps 😉
Source:stackexchange.com