Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define component name in Vue3 setup tag? [duplicate]

In export default {} method, there is a name property to define the component name, which is usefull in dev tool, but what's the equation in new <script setup> tag?

enter image description here

like image 875
Mashiro Avatar asked May 24 '21 09:05

Mashiro


People also ask

How do I name my Vue components?

Component names should always be multi-word, except for root App components, and built-in components provided by Vue, such as <transition> or <component> . This prevents conflicts with existing and future HTML elements, since all HTML elements are a single word.

How do I define a Vue component?

Vue components are written as a combination of JavaScript objects that manage the app's data and an HTML-based template syntax that maps to the underlying DOM structure.

How do I register a component in Vue js?

Local Registration in a Module System Then each of those components can be imported as need may arise before you register them in the new . vue or . js file: import ComponentA from './ComponentA' import ComponentC from './ComponentC' export default { components: { ComponentA, ComponentC }, // ... }

How do I register for Vue component globally?

When we want to globally register a component in Vue, we need to do it in this file. All you have to do is import your component, as you usually would, and then register it using app. component . import { createApp } from 'vue' import App from './App.


1 Answers

Declaring Additional Options

The <script setup> syntax provides the ability to express equivalent functionality of most existing Options API options except for a few:

  • name
  • inheritAttrs
  • Custom options needed by plugins or libraries

If you need to declare these options, use a separate normal block with export default:

<script>
  export default {
    name: 'CustomName',
    inheritAttrs: false,
    customOptions: {}
  }
</script>

<script setup>
  // script setup logic
</script>

Source: link

like image 62
muttering-oldman Avatar answered Sep 28 '22 02:09

muttering-oldman