html:
<div></div>
render code:
_c("div", {}, [])
html:
<div>text</div>
render code:
_c("div", {}, [
_v("text")
])
html:
<div>{{ first }} and {{ secend }}</div>
render code:
_c("div", {}, [
_v( _s(first) + "and" + _s(secend) )
])
html:
<input class="warn" value="default text" :style="innerStyle">
render code:
_c("input", {
attrs: { "class": "warn", "style": innerStyle },
domProps: { "value": "default text" }
}, [])
html:
<div>
<div v-if="a > 0">Item 1</div>
<div v-else-if="b > 0">Item 2</div>
<div v-else>Item 3</div>
</div>
render code:
_c('div', {}, [ /* 留意children数组只有一个元素 */
(a > 0) ? // if
_c('div', {}, [ _v("Item 1") ]) :
(b > 0) ? // elseif
_c('div', {}, [ _v("Item 2") ]) :
// else
_c('div', {}, [ _v("Item 3") ])
])
html:
<div>
<div v-if="a > 0">Item 1</div>
</div>
render code:
_c('div', {}, [ /* 留意children数组只有一个元素 */
(a > 0) ? // if
_c('div', {}, [ _v("Item 1") ]) :
// else
_e() // 产生一个空 VNode
])
html:
<ul>
<li v-for="(item, index) in items">{{ index }} - {{ item }}</li>
</ul>
render code:
_c('ul', {},
_l((items), function(item, index) {
return _c('li', {}, [ _v( _s(index) + " - " + _s(item) ) ])
}
))
html:
<ul>
<li v-for="(item, index) in items" v-if="index == 0">{{ index }} - {{ item }}</li>
</ul>
render code:
_c('ul', {},
_l((items), function(item, index) {
// if 语法编译在 _l 里边,所以 if 里边的表达式可以引用 item 等变量
return (index == 0) ?
_c('li', {}, [ _v( _s(index) + " - " + _s(item) ) ]) :
_e()
}
))
html:
<button v-on:click="clickme">click me</button>
render code:
_c('button', {
on: { "click":clickme }
}, [ _v("click me")] )
html:
<button v-on:click="clickme($event)">click me</button>
render code:
_c('button', {
on: { "click": function($event) { clickme($event) } }
}, [ _v("click me")] )
html:
<button v-on:click.stop="clickme($event)">click me</button>
render code:
_c('button', {
on: { "click": function($event){ $event.stopPropagation(); clickme($event) }
}, [ _v("click me")] )
html:
<input @keyup.enter="submit">
render code:
_c('input', {
on: { "keyup": function($event){
if(_k($event.keyCode, "enter", 13)) return null;
submit($event)
}
}, [ ] )
- _c (tag, data, children) 创建一个非文本 VNode 节点
- _v (text) 创建一个文本VNode节点
- _s (exp) 把 exp 输出成字符串
- _e() 创建一个空的 VNode
- _l (list, render) 渲染一个 VNode 列表
- _k(eventKeyCode, key, builtInAlias) 判定当前事件的按键是否为预期按键值,builtInAlias == eventKeyCode