Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue 源码解析 #83

Open
xiaotiandada opened this issue Aug 19, 2021 · 0 comments
Open

Vue 源码解析 #83

xiaotiandada opened this issue Aug 19, 2021 · 0 comments

Comments

@xiaotiandada
Copy link
Owner

xiaotiandada commented Aug 19, 2021

core/index.js

import Vue from './instance/index'
import { initGlobalAPI } from './global-api/index'

initGlobalAPI(Vue)

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'
// 一个用 Function 实现的类,我们只能通过 new Vue 去实例化它。
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)
}
// 后看这里有很多 xxxMixin 的函数调用,并把 Vue 当参数传入,它们的功能都是给 Vue 的 prototype 上扩展一些方法,
// Vue 按功能把这些扩展分散到多个模块中去实现,而不是在一个模块里实现所有,
// 这种方式是用 Class 难以实现的。这么做的好处是非常方便代码的维护和管理。
initMixin(Vue)
stateMixin(Vue)
eventsMixin(Vue)
lifecycleMixin(Vue)
renderMixin(Vue)

export default Vue
@xiaotiandada xiaotiandada changed the title Vue 源码解析 VUE 源码解析 Aug 19, 2021
@xiaotiandada xiaotiandada changed the title VUE 源码解析 Vue 源码解析 Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant