ready hook

This commit is contained in:
Evan You 2016-04-15 18:37:58 -04:00
parent ab6776161b
commit 11a4addc1b
2 changed files with 19 additions and 16 deletions

View File

@ -35,22 +35,20 @@
Vue.component('select2', {
props: ['options', 'placeholder', 'value'],
template: '#select2-template',
mounted: function () {
ready: function () {
var vm = this
Vue.nextTick(function () {
$(vm.$el)
// init select2
.select2({
data: vm.options,
placeholder: vm.placeholder
})
// emit event on change.
.on('change', function () {
vm.$emit('input', mockEvent(this.value))
})
// set initial value
.select2('val', vm.value)
})
$(this.$el)
// init select2
.select2({
data: this.options,
placeholder: this.placeholder
})
// emit event on change.
.on('change', function () {
vm.$emit('input', mockEvent(this.value))
})
// set initial value
.select2('val', this.value)
},
watch: {
value: function (value) {

View File

@ -1,4 +1,5 @@
import Vue from '../instance/index'
import { callHook } from '../instance/lifecycle'
export default function Component (Ctor, data, parent, children) {
if (typeof Ctor === 'object') {
@ -10,7 +11,7 @@ export default function Component (Ctor, data, parent, children) {
tag: 'component',
key,
data: {
hook: { init, prepatch, destroy },
hook: { init, insert, prepatch, destroy },
Ctor, data, parent, children
}
}
@ -28,6 +29,10 @@ function init (vnode) {
data.child = child
}
function insert (vnode) {
callHook(vnode.child, 'ready')
}
function prepatch (oldVnode, vnode) {
const old = oldVnode.data
const cur = vnode.data