- 模板不是 html,有指令、插值、JS 表达式,能实现判断、循环
- 因此,模板一定是转换为某种 JS 代码,即编译模板
const obj = {a:100, b:200}
with(obj){
console.log(a)
console.log(b)
console.log(c)
}
console.log(obj.c)
<div id="div1" class="container">
<img :src="url" />
<p>a</p>
</div>
with(this){
return createElement(
'div',
{staticClass: "container", attrs: {"id": "div1"}},
[
createElement('img', {attrs: {"src": url}}),
createElement('p', [createTextNode(toString("a"))])
]
)
}
- vue 组件中使用 render 代替 template 就和上面的类似了
Vue.component('test', {
render: function(createElement){
return createElement( )
}
})