Vue
文章
Vue3
- 源码&库Vue3 - 掘金
Vue2
- Vue.js 源码解析 - GitHub
- vue 源码分析 - GitHub
- Vue.js 技术揭秘 - huangyi 源码
- 用一张思维导图总结了 Vue | Vue-Router | Vuex 源码与架构要点 - GitHub
面试题总结
- 历时一个月,2.6W 字!50+Vue 经典面试题源码级详解,你值得收藏! - 掘金
- 又一个月,1.5W 字!50+Vue 经典面试题源码级详解,完结篇! - 掘金
- 「自我检验」熬夜总结 50 个 Vue 知识点,全都会你就是神!!! - 掘金
- 掌握 Vue 的这些高级技巧轻轻松松升职加薪 - 掘金
- 焕然一新的 Vue3 中文文档来了! - 掘金
- 还不会 Vue3 ?一篇笔记带你快速入门 - 掘金
- 10 张脑图带你快速入门 Vue3 | 附高清原图 - 掘金
其他
- Vue3 解构赋值失去响应式引发的思考! - 掘金
- vue 中动态引入图片为什么要是 require, 你不知道的那些事 - 掘金
- vite+vue3+ts 搭建通用后台管理系统 - segmentfault文章
- 我在 vue3 开发中踩的坑 - 掘金
响应式
- 深入了解Vue数据响应式原理 - 微信公众号文章
- 谈谈对 Vue 中双向绑定的理解 - 前端面试题宝典
- 说说 vue3 中的响应式设计原理 - 前端面试题宝典
Vue2 - Object.defineProperty
- 50 行代码的 MVVM,感受闭包的艺术 - 掘金
- 不好意思!耽误你的十分钟,让 MVVM 原理还给你 - 掘金
- 基于 Vue 实现一个简易 MVVM - 掘金
- 剖析 Vue 实现原理 - 如何实现双向绑定 mvvm - GitHub
Vue3 - Proxy
- 面试官: 实现双向绑定 Proxy 比 defineproperty 优劣如何? - 掘金
- 听说你很了解 Vue3 响应式 - 掘金
- 为什么 Vue3.0 不再使用 defineProperty 实现数据监听? - 微信公众号文章
createApp(Vue3)
过程
- createApp runtime-dom/src/index.ts
- nodeOps runtime-dom/src/nodeOps.ts
- createElement、setAttribute等方法
- createRenderer runtime-core/src/renderer.ts
- createAppAPI runtime-core/src/apiCreateApp.ts
js
// runtime-dom/src/index.ts
import { nodeOps } from './nodeOps'
import { patchProp } from './patchProp'
const rendererOptions = /*@__PURE__*/ extend({ patchProp }, nodeOps)
function ensureRenderer() {
return (
renderer ||
(renderer = createRenderer<Node, Element | ShadowRoot>(rendererOptions))
)
}
export const createApp = ((...args) => {
const app = ensureRenderer().createApp(...args)
if (__DEV__) {
injectNativeTagCheck(app)
injectCompilerOptionsCheck(app)
}
const { mount } = app
app.mount = (containerOrSelector: Element | ShadowRoot | string): any => {
// ...
}
return app
})
// runtime-core/src/renderer.ts
export function createRenderer<
HostNode = RendererNode,
HostElement = RendererElement,
>(options: RendererOptions<HostNode, HostElement>): Renderer<HostElement> {
return baseCreateRenderer<HostNode, HostElement>(options)
}
function baseCreateRenderer(...){
const path...
const processText...
const processCommentNode...
const mountStaticNode...
const patchStaticNode...
const moveStaticNode...
const removeStaticNode...
const processElement...
const mountElement...
const setScopeId...
const mountChildren...
const patchElement...
const patchBlockChildren...
const patchProps...
const processFragment...
const processComponent...
const mountComponent...
const updateComponent...
const setupRenderEffect...
const updateComponentPreRender...
const patchChildren...
const patchUnkeyedChildren...
const patchKeyedChildren...
const move...
const unmount...
const remove...
const removeFragment...
const unmountComponent...
const getNextHostNode...
const render...
return {
render,
hydrate,
createApp: createAppAPI(render, hydrate),
}
}
// runtime-core/src/apiCreateApp.ts
export function createAppAPI<HostElement>(
render: RootRenderFunction<HostElement>,
hydrate?: RootHydrateFunction,
): CreateAppFunction<HostElement> {
return function createApp(rootComponent, rootProps = null) {
// ...
const context = createAppContext()
const installedPlugins = new WeakSet()
const pluginCleanupFns: Array<() => any> = []
let isMounted = false
const app: App = (context.app = {
get...
set...
use...
mixin...
component...
directive...
mount...
onUmount...
unmount...
provide...
runWithContext...
})
return app
}
}
生命周期
- 说说你对 Vue 生命周期的理解 - 前端面试题宝典
加载渲染过程
父先创建,才能有子;子创建完成,父才完整。
顺序:父 beforeCreate -> 父 created -> 父 beforeMount -> 子 beforeCreate -> 子 created -> 子 beforeMount -> 子 mounted -> 父 mounted
子组件更新过程
子组件更新 影响到 父组件的情况。
顺序:父 beforeUpdate -> 子 beforeUpdate -> 子 updated -> 父 updated
子组件更新 不影响到 父组件的情况。
顺序:子 beforeUpdate -> 子 updated
父组件更新过程
父组件更新 影响到 子组件的情况。
顺序:父 beforeUpdate -> 子 beforeUpdate -> 子 updated -> 父 updated
父组件更新 不影响到 子组件的情况。
顺序:父 beforeUpdate -> 父 updated
销毁过程
顺序:父 beforeDestroy -> 子 beforeDestroy -> 子 destroyed -> 父 destroyed
模版编译
- 编写一个简单的 JavaScript 模板引擎 - 廖雪峰 - 网站
- JavaScript 模板引擎原理,几行代码的事儿 - 博客
- Vue 模板编译原理 - GitHub
- Vue 模板是如何编译的 - 前端面试题宝典
- vue-loader做了哪些事情? - 前端面试题宝典
- 说说Vue 页面渲染流程 - 前端面试题宝典
- 说说 Vue 中 CSS scoped 的原理 - 前端面试题宝典
VDOM & Diff
Vue2
- 面试官: 你对虚拟 DOM 原理的理解? - 掘金
- 让虚拟 DOM 和 DOM-diff 不再成为你的绊脚石 - 掘金
- 探索 Virtual DOM 的前世今生
- 虚拟 DOM 到底是什么?(长文建议收藏) - segmentfault文章
- 什么是虚拟 DOM?如何实现一个虚拟 DOM?说说你的思路 - 前端面试题宝典
- 手写一个虚拟 DOM 库,彻底让你理解 diff 算法 - 掘金
- 15 张图,20 分钟吃透 Diff 算法核心原理 - 微信公众号文章
key
$nextTick
组件通信
slot
keep-alive
自定义指令
权限控制
其他知识点
css scoped
- 每个组件都会拥有一个[data-v-hash:8]插入HTML标签,子组件标签上也具体父组件[data-v-hash:8];
- 如果style标签加了scoped属性,里面的选择器都会变成(Attribute Selector) [data-v-hash:8];
v-for v-if
- 在 Vue2 当中,v-for的优先级更高,而在 Vue3 当中,则是v-if的优先级更高。