temmplate 模板使用
1 这两种写法几乎一致 只是是否简写
const demo ={
template:'<div> <h2>hello </h2></div> '
}
const app = Vue.createApp(demo);
app.mount("#app")
Vue.createApp({
template:`<h2>hello vue3</h2>`
}).mount('#app')
2定义 script的 type为 x-template 使用起来和 上门的1差不多
<script type="x-template" id="tem">
<div>
<h2>{{msg}}</h2>
<h2>{{counter}}</h2>
<button @click='add'>+1</button>
<button @click='jian'>-1</button>
</div>
</script>
在template中 通过 id获取
template:'#tem',
3.最好用的方法 在 body中 直接使用 template 同样是 在template中 通过 id获取
<body>
<div id="app">
</div>
<template id="tem">
<div>
<h2>{{msg}}</h2>
<h2>{{counter}}</h2>
<button @click='add'>+1</button>
<button @click='jian'>-1</button>
<button @click="btnClick">button</button>
<button @click="btn2Click">2</button>
</div>
</template>
</body>