最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How can I use kebab-case for naming components in Vue? - Stack Overflow

matteradmin6PV0评论

I'd like to use snake_case on the names of ponents when I call its name on the tag within the template. I just tried:

<script>
import footer-goodfooter from "@/p/footer/c_footer.vue";
^^^^^^^^^^^^^^                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 'import ... =' can only be used in TypeScript files.Vetur(8002)

export default {
  name: 'App',
  ponents: {
    footer-goodfooter,
          ^
// ',' expected.Vetur(1005)
  },

But I want my ponent(in this case, footer-goodfooter) below inside the template like this:

<main>
   <header-bigheader />
   <content-fat-superfat-hallelujah />
   <footer-goodfooter />
</main>

How can I achieve this? Thank you.

I'd like to use snake_case on the names of ponents when I call its name on the tag within the template. I just tried:

<script>
import footer-goodfooter from "@/p/footer/c_footer.vue";
^^^^^^^^^^^^^^                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// 'import ... =' can only be used in TypeScript files.Vetur(8002)

export default {
  name: 'App',
  ponents: {
    footer-goodfooter,
          ^
// ',' expected.Vetur(1005)
  },

But I want my ponent(in this case, footer-goodfooter) below inside the template like this:

<main>
   <header-bigheader />
   <content-fat-superfat-hallelujah />
   <footer-goodfooter />
</main>

How can I achieve this? Thank you.

Share Improve this question edited Dec 28, 2021 at 14:04 Penny Liu 17.6k5 gold badges86 silver badges108 bronze badges asked Aug 24, 2021 at 12:31 LeeLee 621 silver badge10 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Components are PascalCase in Vue, but in the template they can be called via kebab-case

<template>
  <footer-good-footer />
</template>

<script lang="ts">
import FooterGoodFooter from "@/p/footer/c_footer.vue";

export default {
  name: 'App',
  ponents: {
    FooterGoodFooter, // OR 'custom-name': footerGoodFooter
  }
}
</script>

AFAIK the file name should not matter here.

See: https://v2.vuejs/v2/guide/ponents-registration.html#Local-Registration

I really don´t know if I understand your question. But if you want to achieve to call a ponent in your template like:

<single-filter-container></single-filter-container>

... then just do the export in the singleFilterContainer.vue like:

export default {
   name: "singleFilterContainer"
}

... import this ponent into it´s parent like:

import SingleFilterContainer from "@/ponents/singleFilterContainer";

... and use it in your template like:

<single-filter-container></single-filter-container>

As far es I know, this is a normal usecase, so there shouldn´t be any workaround needed. It is remended in the Style Guide of Vue.js. Please try it as I mentioned and give some feedback, if it doesn´t work.

If so, we can check if there is any problem with one of your modules or your IDE have a plugin for autoplete this for you. I am using Vue 3 and working on IntelliJ with Vue.js plugin.

Post a comment

comment list (0)

  1. No comments so far