[TOC]
*****
## web-runtime-with-compiler web運行編譯時
>[info] import
~~~
;(導入)編譯運行時
import config from 'core/config'
import { warn, cached } from 'core/util/index'
import { query } from 'web/util/index'
import Vue from './web-runtime'
import { compileToFunctions } from './web-compiler'
~~~
>[info] module
~~~
;獲取元素模板
const idToTemplate = cached(id => query(id).innerHTML)
;保存mount接口
const mount = Vue.prototype.$mount
;編譯運行時$mount修正
Vue.prototype.$mount = function (el) {
;獲取元素
el = el && query(el)
;選項
const options = this.$options
;檢查是否包含渲染選項
if (!options.render) {
;獲取模板選項
let template = options.template
;檢查是否已包含模板
if (template) {
if (typeof template === 'string') {
if (template.charAt(0) === '#') {
template = idToTemplate(template)
}
} else if (template.nodeType) {
template = template.innerHTML
} else {
warn('invalid template option:' + template, this)
}
} else if (el) {
;生成模板
template = getOuterHTML(el)
}
;檢查模板
if (template) {
;生成render,staticRenderFns函數
const { render, staticRenderFns } = compileToFunctions(template, {
preserveWhitespace: config.preserveWhitespace,
delimiters: options.delimiters
})
;掛載到options
options.render = render
options.staticRenderFns = staticRenderFns
}
}
;調用原生mount函數實現掛載
mount.call(this, el)
}
;獲取el的模板
function getOuterHTML (el) {
if (el.outerHTML) {
return el.outerHTML
} else {
const container = document.createElement('div')
container.appendChild(el.cloneNode(true))
return container.innerHTML
}
}
;編譯入口
Vue.compile = compileToFunctions
;編譯運行時Vue
export default Vue
~~~
>[info] export
~~~
;(導出)編譯運行時Vue
export default Vue
~~~
- 概述
- 框架結構
- 編譯入口(\entries)
- web-compiler.js(web編譯)
- web-runtime.js(web運行時)
- web-runtime-wih-compiler.js(web編譯運行)
- web-server-renderer.js(web服務器渲染)
- 核心實現 (\core)
- index.js(核心入口)
- config.js(核心配置)
- core\util(核心工具)
- core\observer(雙向綁定)
- core\vdom(虛擬DOM)
- core\global-api(核心api)
- core\instance(核心實例)
- 模板編譯(\compiler)
- compiler\parser(模板解析)
- events.js(事件解析)
- helper.js(解析助手)
- directives\ref.js(ref指令)
- optimizer.js(解析優化)
- codegen.js(渲染生成)
- index.js(模板編譯入口)
- web渲染(\platforms\web)
- compiler(web編譯目錄)
- runtime(web運行時目錄)
- server(web服務器目錄)
- util(web工具目錄)
- 服務器渲染(\server)
- render-stream.js(流式渲染)
- render.js(服務器渲染函數)
- create-renderer.js(創建渲染接口)
- 框架流程
- Vue初始化
- Vue視圖數據綁定
- Vue數據變化刷新
- Vue視圖操作刷新
- 框架工具
- 基礎工具(\shared)
- 模板編譯助手
- 核心實例工具
- Web渲染工具
- 基礎原理
- dom
- string
- array
- function
- object
- es6
- 模塊(Module)
- 類(Class)
- 函數(箭頭)
- 字符串(擴展)
- 代理接口(Proxy)
- 數據綁定基礎
- 數據綁定實現
- mvvm簡單實現
- mvvm簡單使用
- vdom算法
- vdom實現
- vue源碼分析資料