You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
...
if (el.key) {
data += `key:${el.key},`
}
// ref
if (el.ref) {
data += `ref:${el.ref},`
}
...
if (el.attrs) {
data += `attrs:{${genProps(el.attrs)}},`
}
if (el.props) {
data += `domProps:{${genProps(el.props)}},`
}
if (el.events) {
data += `${genHandlers(el.events, false, state.warn)},`
}
...
Uh oh!
There was an error while loading. Please reload this page.
指令是
模板解析
的续章,本文会尝试从源码的角度来理解指令
是如何被提取和应用的。指令的提取
指令的提取过程是在parse阶段进行的,在
parseHTML
方法中,会解析字符串模板为如下的单个ast对象通过提取为格式化的对象,就可以对单个的节点进行解析了
指令的解析
首先对
v-for
,v-if
,v-once
三个指令进行解析指令的处理
通过上面的步骤,Vue 提取出了
props
,events
,attrsMap
,for
等指令对象,那么 Vue 又是如何去处理这些指令的呢?codegen/index.js
中有这样一些代码:上面这些代码会对每个属性进行处理,然后拼接为字符串
剩下的事情,就交给
vm.$createElement
去生成vNode了。The text was updated successfully, but these errors were encountered: