文件名
完整版与运行时版(不完整版)
完整版中使用template
完整版vue一般使用template来创建HTML,template是一个替换挂载的元素模板,使用html的方式做渲染。
new Vue({
el:'#app',
template :`
<div>
{{n}}
<button @click="add">+1</button>
</div>
`
})
运行时版使用render
vue中的render函数中有一个参数,这个参数是一个函数通常我们叫做h。Render函数将h的返回值放到了HTML中。
new Vue({
el:'#app',
render(h) {
return h('div',[this.n,h('button',{on:{click:this.add}},'+1')])
},
使用codesandbox
你也可以使用codesandbox在线写Vue代码
1.进入codesandbox
2.不需要登录,选择create sandbox创建一个vue沙盒
3.编写完成后点击File,选择export to zip,然后就可以导入本地了