入口文件
入口文件的位置:src/core/instance/index.js
import { initMixin } from './init'
import { stateMixin } from './state'
import { renderMixin } from './render'
import { eventsMixin } from './events'
import { lifecycleMixin } from './lifecycle'
import { warn } from '../util/index'
/**
* 定义构造函数 Vue
* @param {*} options,{el: '#app',router,components: { App },template: '<App/>',}
*/
function Vue (options) {
// 非生产环境下,如果this的实例不是Vue,警告提示
if (process.env.NODE_ENV !== 'production' && !(this instanceof Vue)) {
warn('Vue is a constructor and should be called with the `new` keyword')
}
// 初始化
this._init(options)
}
initMixin(Vue) // Vue.prototye上添加了_init方法
stateMixin(Vue) // Vue.prototye上定义了属性: $data、$props,方法:$set、$delete、$watch
eventsMixin(Vue)// Vue.prototye上添加了四个方法: $on、 $once 、$off 、$emit
lifecycleMixin(Vue)// lifecycleMixin(Vue),在原型Vue.prototye上添加了三个方法:_update 、$forceUpdate 、$destory
renderMixin(Vue)// Vue.prototye上添加了方法:$nextTick 、_render、 _o、 _n、 _s、 _l、 _t、 _q、 _i、 _m、 _f、 _k、 _b、 _v、 _e、 _u、 _g、 _d、 _p
export default Vue作用:
定义
Vue构造函数,并暴露Vue方法调用五个
mixin混入方法,在Vue的原型prototype上添加不同的属性和方法
这个时候,我们知道了,我们在new Vue()的时候,实际上就是调用this._init(options)方法。options包括:data,props,computed,methods,watch,el,template等 选项列表
五个mixin方法,作用是在Vue的原型上添加相关的属性和方法:
initMixin(Vue)
作用:Vue.prototye上添加
_init方法stateMixin(Vue)
作用:Vue.prototye上添加属性:
$data、$props,方法:$set、$delete、$watcheventsMixin(Vue)
作用:Vue.prototye上添加四个方法:
$on、 $once 、$off 、$emitlifecycleMixin(Vue)
作用:Vue.prototye上添加三个方法:
_update 、$forceUpdate 、$destoryrenderMixin(Vue)
作用:Vue.prototye上添加方法:
$nextTick 、_render、 _o、 _n、 _s、 _l、 _t、 _q、 _i、 _m、 _f、 _k、 _b、 _v、 _e、 _u、 _g、 _d、 _p
一、initMixin(Vue) 作用:在Vue的原型上添加一个_init方法
二、stateMixin(Vue) 作用:在Vue的原型上添加了如下两个属性:$data、$props;三个方法:$set、$delete、$watch
三、eventsMixin(Vue) 作用:在原型上添加了四个方法: $on、 $once 、$off 、$emit
四、lifecycleMixin(Vue) 作用:在Vue.prototye上添加了三个方法:_update 、$forceUpdate 、$destory
五、renderMixin(Vue) 作用:在原型上添加了方法:$nextTick 、_render、 _o、 _n、 _s、 _l、 _t、 _q、 _i、 _m、 _f、 _k、 _b、 _v、 _e、 _u、 _g、 _d、 _p
接下来,我们看看import Vue from 'vue'时做了什么下一章
Last updated
Was this helpful?