VueJS 3.0 provides new syntax for defining component

().

import { defineComponent, ref } from 'vue' const HelloWorld = defineComponent(function HelloWorld() { const count = ref(0) return { count } }) 

How to locally register components with passing function to defineComponent?

In old style you are to use components field in component definition object like this:

import ComponentA from './ComponentA.vue' export default { components: { ComponentA } // ... } 

1 Answer

You could do it simply as before by adding that component to components option :

import ComponentA from './ComponentA.vue' export default defineComponent({ setup() { const count = ref(0) return { count } }, components: { ComponentA } }); 

LIVE DEMO

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy