[Vuejs]-Dynamically Create Props

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
    }
  }
})

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 😉

Leave a comment