Vue.component('component_name', {
props: ['prop_name'],
template: '<div class="root"></div>',
data() {
return {}
},
methods: {
},
created() {
}
});
If you are using build steps and want to create the components in your .vue file then you can use the below code example to define a new component.
counter.vue file
<script>
export default {
data() {
return {
count: 0
}
}
}
</script>
<template>
<button @click="count++">Counter: {{ count }}</button>
</template>
We have created a file counter.vue for our component and placed the above code. We have defined a variable count that starts from 0 and on button click, we are increasing it's value by 1.
0 Comments