Skip to content

Instantly share code, notes, and snippets.

@oxfordyang2016
Created April 12, 2022 13:29
Show Gist options
  • Save oxfordyang2016/9474468df3ff58ca74f1f6446b5abf6c to your computer and use it in GitHub Desktop.
Save oxfordyang2016/9474468df3ff58ca74f1f6446b5abf6c to your computer and use it in GitHub Desktop.
Component basics
<div id="components-demo">
<button-counter></button-counter>
</div>
// Create a Vue application
const app = Vue.createApp({})
// Define a new global component called button-counter
app.component('button-counter', {
data() {
return {
count: 0
}
},
template: `
<button v-on:click="count++">
You clicked me {{ count }} times.
</button>`
})
app.mount('#components-demo')
<script src="https://unpkg.com/vue@next"></script>
.demo {
font-family: sans-serif;
border: 1px solid #eee;
border-radius: 2px;
padding: 20px 30px;
margin-top: 1em;
margin-bottom: 40px;
user-select: none;
overflow-x: auto;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment