Skip to content

Instantly share code, notes, and snippets.

@asselin
Last active February 9, 2017 20:58
Show Gist options
  • Select an option

  • Save asselin/0b9c1da1015858bd58d7423cba1645bd to your computer and use it in GitHub Desktop.

Select an option

Save asselin/0b9c1da1015858bd58d7423cba1645bd to your computer and use it in GitHub Desktop.
Dynamically extending a Vue Object
import Vue from 'Vue';
beforeCreate () {
this.$options = Vue.util.mergeOptions({
data: function() {
return {
selectedItem: 8
}
},
computed: {
computeFoo: function() {
return this.selectedItem * 2;
}
},
methods: {
foo: function() {
console.log('hello');
}
}
}, this.$options, this);
// From a passed in prop
this.$options = Vue.util.mergeOptions(this.$options.propsData.passedInMixin, this.$options, this);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment