Skip to content

Commit 11a4add

Browse files
committed
ready hook
1 parent ab67761 commit 11a4add

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

Diff for: examples/select2/index.html

+13-15
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,20 @@
3535
Vue.component('select2', {
3636
props: ['options', 'placeholder', 'value'],
3737
template: '#select2-template',
38-
mounted: function () {
38+
ready: function () {
3939
var vm = this
40-
Vue.nextTick(function () {
41-
$(vm.$el)
42-
// init select2
43-
.select2({
44-
data: vm.options,
45-
placeholder: vm.placeholder
46-
})
47-
// emit event on change.
48-
.on('change', function () {
49-
vm.$emit('input', mockEvent(this.value))
50-
})
51-
// set initial value
52-
.select2('val', vm.value)
53-
})
40+
$(this.$el)
41+
// init select2
42+
.select2({
43+
data: this.options,
44+
placeholder: this.placeholder
45+
})
46+
// emit event on change.
47+
.on('change', function () {
48+
vm.$emit('input', mockEvent(this.value))
49+
})
50+
// set initial value
51+
.select2('val', this.value)
5452
},
5553
watch: {
5654
value: function (value) {

Diff for: src/runtime/vdom/component.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Vue from '../instance/index'
2+
import { callHook } from '../instance/lifecycle'
23

34
export default function Component (Ctor, data, parent, children) {
45
if (typeof Ctor === 'object') {
@@ -10,7 +11,7 @@ export default function Component (Ctor, data, parent, children) {
1011
tag: 'component',
1112
key,
1213
data: {
13-
hook: { init, prepatch, destroy },
14+
hook: { init, insert, prepatch, destroy },
1415
Ctor, data, parent, children
1516
}
1617
}
@@ -28,6 +29,10 @@ function init (vnode) {
2829
data.child = child
2930
}
3031

32+
function insert (vnode) {
33+
callHook(vnode.child, 'ready')
34+
}
35+
3136
function prepatch (oldVnode, vnode) {
3237
const old = oldVnode.data
3338
const cur = vnode.data

0 commit comments

Comments
 (0)