I’m a beginner in vue js. how can declare template block when using vue js cdn?
I assume you’re referring to <template>
within a single file component. You can’t use SFC’s with the CDN version of Vue as SFC’s have to be compiled with a build tool.
You can use <script type="text/x-template">
with the CDN version.
Example: https://codepen.io/getreworked/pen/jOaNEXo
<div id="components-demo">
<button-counter></button-counter>
</div>
<script id="counter" type="text/x-template">
<button v-on:click="count++">
You clicked me {{ count }} times.
</button>
</script>
const app = Vue.createApp({})
app.component('button-counter', {
data() {
return {
count: 0
}
},
template: `#counter`
})
app.mount('#components-demo')
1 Like
Thank you for your help!