github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/libs/vue-1.0.24/src/instance/api/lifecycle.js (about) 1 import { warn, query, inDoc } from '../../util/index' 2 import { compile } from '../../compiler/index' 3 4 export default function (Vue) { 5 /** 6 * Set instance target element and kick off the compilation 7 * process. The passed in `el` can be a selector string, an 8 * existing Element, or a DocumentFragment (for block 9 * instances). 10 * 11 * @param {Element|DocumentFragment|string} el 12 * @public 13 */ 14 15 Vue.prototype.$mount = function (el) { 16 if (this._isCompiled) { 17 process.env.NODE_ENV !== 'production' && warn( 18 '$mount() should be called only once.', 19 this 20 ) 21 return 22 } 23 el = query(el) 24 if (!el) { 25 el = document.createElement('div') 26 } 27 this._compile(el) 28 this._initDOMHooks() 29 if (inDoc(this.$el)) { 30 this._callHook('attached') 31 ready.call(this) 32 } else { 33 this.$once('hook:attached', ready) 34 } 35 return this 36 } 37 38 /** 39 * Mark an instance as ready. 40 */ 41 42 function ready () { 43 this._isAttached = true 44 this._isReady = true 45 this._callHook('ready') 46 } 47 48 /** 49 * Teardown the instance, simply delegate to the internal 50 * _destroy. 51 * 52 * @param {Boolean} remove 53 * @param {Boolean} deferCleanup 54 */ 55 56 Vue.prototype.$destroy = function (remove, deferCleanup) { 57 this._destroy(remove, deferCleanup) 58 } 59 60 /** 61 * Partially compile a piece of DOM and return a 62 * decompile function. 63 * 64 * @param {Element|DocumentFragment} el 65 * @param {Vue} [host] 66 * @param {Object} [scope] 67 * @param {Fragment} [frag] 68 * @return {Function} 69 */ 70 71 Vue.prototype.$compile = function (el, host, scope, frag) { 72 return compile(el, this.$options, true)( 73 this, el, host, scope, frag 74 ) 75 } 76 }