vue解析系列(二):core vue & instance vue

core vue github.com/vuejs/vue/b…

import Vue from './instance/index'
// 引入初始化全局api函数
import {
  initGlobalAPI
} from './global-api/index'
// 引入服务端端判断变量
import {
  isServerRendering
} from 'core/util/env'
// 引入函数组件context构造函数
import {
  FunctionalRenderContext
} from 'core/vdom/create-functional-component'

// 添加静态方法
initGlobalAPI(Vue)

// 添加$isServer属性get方法
Object.defineProperty(Vue.prototype, '$isServer', {
  get: isServerRendering
})

// 添加$ssrContext属性get方法
Object.defineProperty(Vue.prototype, '$ssrContext', {
  get () {
    /* istanbul ignore next */
    return this.$vnode && this.$vnode.ssrContext
  }
})

// 添加FunctionalRenderContext属性的value
Object.defineProperty(Vue, 'FunctionalRenderContext', {
  value: FunctionalRenderContext
})

// rollup打包时替换为vue的版本号
Vue.version = '__VERSION__'

export default Vue

复制代码

instance vue github.com/vuejs/vue/b…

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)
}

// 添加init方法
initMixin(Vue)

// 添加$props $data $watch $set $del属性
stateMixin(Vue)

// $on $once $emit $off
eventsMixin(Vue)

// _update $forceUpdate $destroy
lifecycleMixin(Vue)

// $nextTick _render
renderMixin(Vue)

export default Vue
复制代码

转载于:https://juejin.im/post/5ccd9be2e51d453b440236ca

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值