版本:2.5.17-beta.0

核心模块(src/core):包括组件、全局API、vue实例、对象属性监测系统、公共方法、虚拟dom、配置等模块

src/core/index.js

import Vue from './instance/index'
import { initGlobalAPI } from './global-api/index'
import { isServerRendering } from 'core/util/env'
import { FunctionalRenderContext } from 'core/vdom/create-functional-component'
//添加全局api
initGlobalAPI(Vue)
//服务端 运行判断
Object.defineProperty(Vue.prototype, '$isServer', {
get: isServerRendering
})
//处理内存泄漏 处理
Object.defineProperty(Vue.prototype, '$ssrContext', {
get () {
/* istanbul ignore next */
return this.$vnode && this.$vnode.ssrContext
}
})
// 不知道干啥的todo
Object.defineProperty(Vue, 'FunctionalRenderContext', {
value: FunctionalRenderContext
})
//__VERSION__是配置的变量
Vue.version = '__VERSION__'
export default Vue

突然发现源码 读起来还好 写出来怎么那么麻烦啊!

initGlobalApi

/* @flow */

import config from '../config'
import { initUse } from './use'
import { initMixin } from './mixin'
import { initExtend } from './extend'
import { initAssetRegisters } from './assets'
import { set, del } from '../observer/index'
import { ASSET_TYPES } from 'shared/constants'
import builtInComponents from '../components/index' import {
warn,
extend,
nextTick,
mergeOptions,
defineReactive
} from '../util/index' export function initGlobalAPI (Vue: GlobalAPI) {
// config
const configDef = {}
configDef.get = () => config
if (process.env.NODE_ENV !== 'production') {
configDef.set = () => {
warn(
'Do not replace the Vue.config object, set individual fields instead.'
)
}
}
Object.defineProperty(Vue, 'config', configDef) // exposed util methods.
// NOTE: these are not considered part of the public API - avoid relying on
// them unless you are aware of the risk. //在这个地方挂载 util方法
Vue.util = {
warn,
extend,
mergeOptions, //合并options.js
defineReactive //
}
Vue.set = set
Vue.delete = del //方法来自 "../util/index"
Vue.nextTick = nextTick Vue.options = Object.create(null)
ASSET_TYPES.forEach(type => {
Vue.options[type + 's'] = Object.create(null)
}) // this is used to identify the "base" constructor to extend all plain-object
// components with in Weex's multi-instance scenarios.
Vue.options._base = Vue //keep-alive 组件,点进去就可以看到
extend(Vue.options.components, builtInComponents) //Vue.use()方法
initUse(Vue) //Vue.mixin()方法
initMixin(Vue) //Vue.extend() 方法
initExtend(Vue) //Vue.component, Vue.directive, Vue.filter
initAssetRegisters(Vue)
}

util 方法 extend,mergeOptions,defineReactive,nextTick

extend

/**
* 简单的对象的浅拷贝,有点失望
*/
export function extend (to: Object, _from: ?Object): Object {
for (const key in _from) {
to[key] = _from[key]
}
return to
}

写出来真麻烦

vue源码阅读(一)的更多相关文章

  1. vue源码阅读(二)

    一 一个实例 如果简单了解过些Vue的API的话,肯定会对一下这个特别熟悉,在上一篇里,分析了Vue的核心文件core的index.js构造vue函数执行的流程. 那么下边这个则是实例化构造函数,也就 ...

  2. Vue源码阅读一:说说vue.nextTick实现

    用法: 在下次 DOM 更新循环结束之后执行延迟回调.在修改数据之后立即使用这个方法,获取更新后的 DOM. 疑惑: 怎么实现的延迟回调 原理: JavaScript语言的一大特点就是单线程,同一个时 ...

  3. vue源码阅读笔记

    1.yarn test [文件名]  -t [name-of-spec(describe or test )] 直接运行yarn test,会测试所有测试文件:yarn test 后面只跟文件名的话会 ...

  4. vue 源码阅读记录

    0.webpack默认引入的是vue.runtime.common.js,并不是vue.js,功能有略微差别,不影响使用 1.阅读由ts编译后的js: 入口>构造函数 >定义各类方法 &g ...

  5. 【一套代码小程序&Native&Web阶段总结篇】可以这样阅读Vue源码

    前言 前面我们对微信小程序进行了研究:[微信小程序项目实践总结]30分钟从陌生到熟悉 在实际代码过程中我们发现,我们可能又要做H5站又要做小程序同时还要做个APP,这里会造成很大的资源浪费,如果设定一 ...

  6. 阅读vue源码-----内置组件篇(keep-alive)

    1.前言: <keep-alive>是vue实现的一个内置组件,也就是说vue源码不仅实现了一套组件化的机制,也实现了一些内置组件. <keep-alive>官网介绍如下:&l ...

  7. 大白话Vue源码系列(01):万事开头难

    阅读目录 Vue 的源码目录结构 预备知识 先捡软的捏 Angular 是 Google 亲儿子,React 是 Facebook 小正太,那咱为啥偏偏选择了 Vue 下手,一句话,Vue 是咱见过的 ...

  8. 大白话Vue源码系列(02):编译器初探

    阅读目录 编译器代码藏在哪 Vue.prototype.$mount 构建 AST 的一般过程 Vue 构建的 AST 题接上文,上回书说到,Vue 的编译器模块相对独立且简单,那咱们就从这块入手,先 ...

  9. 大白话Vue源码系列(03):生成AST

    阅读目录 AST 节点定义 标签的正则匹配 解析用到的工具方法 解析开始标签 解析结束标签 解析文本 解析整块 HTML 模板 未提及的细节 本篇探讨 Vue 根据 html 模板片段构建出 AST ...

随机推荐

  1. luogu 3166 组合与gcd(数三角形)结论

    在n*m的点格图中选取三个点满足三角形的个数 结论:点(x1,y1)和(x2,y2) 中间有gcd(x2-x1,y2-y1)+1个和两点连成的线段直线共线 那么大力枚举 x2-x1和y2-y1,然后发 ...

  2. windows 7中的windows键相关的快捷键

    引用 https://support.microsoft.com/zh-cn/help/976857 Windows 键的位置 如果不清楚 Windows 键的位置,请参照下图: 常用的 Window ...

  3. 转载-CentOS7关闭防火墙

    原文地址-http://www.cnblogs.com/silent2012/archive/2015/07/28/4682770.html CentOS 7.0默认使用的是firewall作为防火墙 ...

  4. Leetcode#70. Climbing Stairs(爬楼梯)

    题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解 ...

  5. javascript基础 之 void

    1,viod是什么? javascript:void(0) 这样的代码是js中很常用的代码,void是javascript中定义的一个操作符,void后面跟一个表达式,void操作符会立即执行后面的表 ...

  6. 第四节,目标检测---YOLO系列

    1.R-CNN回顾 适应全卷积化CNN结构,提出全卷积化设计 共享ResNet的所有卷积层 引入变换敏感性(Translation variance) 位置敏感分值图(Position-sensiti ...

  7. Lua中的迭代器与泛型for

    [前言] 迭代器就是一种可以遍历一种集合中所有元素的机制,在Lua中,通常将迭代器表示为函数.每调用一次函数,就返回集合中的“下一个”元素.每个迭代器都需要在每次成功调用之后保存一些状态,这样才能知道 ...

  8. RabbitMQ 消息队列 二

    一:查看MQ的用户角色 rabbitmqctl list_users 二:添加新的角色,并授予权限 rabbitmqctl add_user xiaoyao 123456 rabbitmqctl se ...

  9. mybatis循环、mybatis传map

    mybatis中使用循环.mybatis传入map案例 <!-- 根据id修改商户提成配置--> <update id="editStopAll" paramet ...

  10. selenium之使用chrome浏览器测试(附chromedriver与chrome的对应关系表)

    https://www.cnblogs.com/JHblogs/p/7699951.html