https://github.com/vuejs/vue-class-component/issues/87
by ktsn
HTML
<div id="app"></div>
<!-- Importing libs and setup -->
<script src="https://unpkg.com/vue@latest/dist/vue.js"></script>
Babel + JSX
const App1 = Vue.extend({
template: '<p>{{ message }}</p>',
data () {
return {
message: 'beforeCreate is not called'
}
},
beforeCreate () {
setTimeout(() => {
this.message = 'beforeCreate is called'
}, 1000)
}
})
const App2 = {
template: '<p>{{ message }}</p>',
data () {
return {
message: 'beforeCreate is not called'
}
},
beforeCreate () {
setTimeout(() => {
this.message = 'beforeCreate is called'
}, 1000)
}
}
Vue.mixin({
beforeCreate () {
console.log('Global mixin')
}
})
function injected () {
console.log('Injected')
}
App1.options.beforeCreate.push(injected)
App2.beforeCreate = [App2.options.beforeCreate, injected]
new Vue({
el: '#app',
render (h) {
return h('div', [
h(App1),
h(App2)
])
}
})