Evan You 10 lat temu
rodzic
commit
11a4addc1b
2 zmienionych plików z 19 dodań i 16 usunięć
  1. 13 15
      examples/select2/index.html
  2. 6 1
      src/runtime/vdom/component.js

+ 13 - 15
examples/select2/index.html

@@ -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) {

+ 6 - 1
src/runtime/vdom/component.js

@@ -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