vue源码阅读(一)
版本: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源码阅读(一)的更多相关文章
- vue源码阅读(二)
一 一个实例 如果简单了解过些Vue的API的话,肯定会对一下这个特别熟悉,在上一篇里,分析了Vue的核心文件core的index.js构造vue函数执行的流程. 那么下边这个则是实例化构造函数,也就 ...
- Vue源码阅读一:说说vue.nextTick实现
用法: 在下次 DOM 更新循环结束之后执行延迟回调.在修改数据之后立即使用这个方法,获取更新后的 DOM. 疑惑: 怎么实现的延迟回调 原理: JavaScript语言的一大特点就是单线程,同一个时 ...
- vue源码阅读笔记
1.yarn test [文件名] -t [name-of-spec(describe or test )] 直接运行yarn test,会测试所有测试文件:yarn test 后面只跟文件名的话会 ...
- vue 源码阅读记录
0.webpack默认引入的是vue.runtime.common.js,并不是vue.js,功能有略微差别,不影响使用 1.阅读由ts编译后的js: 入口>构造函数 >定义各类方法 &g ...
- 【一套代码小程序&Native&Web阶段总结篇】可以这样阅读Vue源码
前言 前面我们对微信小程序进行了研究:[微信小程序项目实践总结]30分钟从陌生到熟悉 在实际代码过程中我们发现,我们可能又要做H5站又要做小程序同时还要做个APP,这里会造成很大的资源浪费,如果设定一 ...
- 阅读vue源码-----内置组件篇(keep-alive)
1.前言: <keep-alive>是vue实现的一个内置组件,也就是说vue源码不仅实现了一套组件化的机制,也实现了一些内置组件. <keep-alive>官网介绍如下:&l ...
- 大白话Vue源码系列(01):万事开头难
阅读目录 Vue 的源码目录结构 预备知识 先捡软的捏 Angular 是 Google 亲儿子,React 是 Facebook 小正太,那咱为啥偏偏选择了 Vue 下手,一句话,Vue 是咱见过的 ...
- 大白话Vue源码系列(02):编译器初探
阅读目录 编译器代码藏在哪 Vue.prototype.$mount 构建 AST 的一般过程 Vue 构建的 AST 题接上文,上回书说到,Vue 的编译器模块相对独立且简单,那咱们就从这块入手,先 ...
- 大白话Vue源码系列(03):生成AST
阅读目录 AST 节点定义 标签的正则匹配 解析用到的工具方法 解析开始标签 解析结束标签 解析文本 解析整块 HTML 模板 未提及的细节 本篇探讨 Vue 根据 html 模板片段构建出 AST ...
随机推荐
- SHAREDPOOL使用率的监控部署及思考
[系统环境]: 系统环境:Sun Solaris10 U11 + ORACLE 11.2.0.4.0 RAC [背景描述]: 从2016年11月起,生产的数据库期的出现了两次m0001进程12 ...
- [物理学与PDEs]第3章第1节 等离子体
1. 磁流体力学研究等离子体这种导电流体在电磁场中的运动. 2. 任何物质由于 $T, p$ 等条件的不同而可以处于固态.液态.气态 (常见的三种聚集态) 或等离子体. 3. 等离子体就是电离气 ...
- C#中访问私有成员技巧
源代码是别人的,你就不能修改源代码,只提供给你dll.或者你去维护别人的代码,源代码却有丢失.这样的情况如果你想知道私有成员的值,甚至去想直接调用类里面的私有方法.那怎么办呢?其实在.net中访问私有 ...
- UE4 PostProcessVolume笔记
透镜:Lens Bloom 光溢出 VDirt Mask 光溢出泥土蒙版 Depth of Filed 景深 V Eye Adaptation (Auto-Exposure) 人眼适应 V这个效果有时 ...
- 2018年7月6日go语言学习
Go是一门并发支持.垃圾回收的编译型系统编程语言. 特点:类型安全和内存安全 以非常直观和极低的方案实现高并发 高效的垃圾回收机制 快速编译 为多核计算机提供性能提升方案 Utf-8编码支持 Go源码 ...
- stm32F10x复习-1
地点:家 1.库文件说明 _htmresc: LOGO的设计图 Libraries: 源代码及启动文件 -- CoreSupport 核内设备函数层的CM3核通用的源文件.作用是为采用Cortex-M ...
- 论文笔记:Deep feature learning with relative distance comparison for person re-identification
这篇论文是要解决 person re-identification 的问题.所谓 person re-identification,指的是在不同的场景下识别同一个人(如下图所示).这里的难点是,由于不 ...
- JS 对Array集合排序的方法
我的业务是根据距离的远近经行一个排序: 第一种方法:冒泡排序 排序前的数据是这样子的: 排序后是这样子的: 代码可以直接复制使用的: <!doctype html> <html> ...
- All about Using Burp Suite
1.how to use burpsuite I can't thank them enough for allowing us to test web application ,making su ...
- post 数据
可参照:http://www.voidcn.com/blog/Vindra/article/p-4917667.html 一.get请求 curl "http://www.baidu.com ...