mirror of
https://github.com/vuejs/vue.git
synced 2024-11-22 04:39:46 +00:00
ready hook
This commit is contained in:
parent
ab6776161b
commit
11a4addc1b
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user