instance/index.js
来源:2-2 new Vue 发生了什么

我要学习去了
2020-09-03
黄老师,关于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'
function Vue (options) {
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)
stateMixin(Vue)
eventsMixin(Vue)
lifecycleMixin(Vue)
renderMixin(Vue)
export default Vue
- 这里_init方法是哪里来的呀,是那个定义在init.js上的原型方法吗?
- 这个_init方法没有定义为什么不会报错?
- 那下面的一堆minx函数为什么需要引入呀,,他又不用导出给其他文件,有什意义?
写回答
1回答
-
ustbhuangyi
2020-09-04
_init 是定义在 Vue 原型上的方法啊,在 initMinxin 中就定义的
mixin 函数就是给 Vue 原型扩展各种方法,课程中应该讲了吧00
相似问题