36

I am new In Vue.js Technology. I am getting an error while running my Vue application. Don't know where I am wrong, please try to fix my error.

This is the Temp File where I am getting an Error.

Temp.vue

<template>
  <div>
    <h1>Hello Ashish</h1>
    <h2>{{name}}</h2>
  </div>
</template>

<script>
export default {
  name: "Temp",
};
</script>

App.vue

<template>
  <img alt="Vue logo" src="./assets/logo.png">
  <HelloWorld msg="Welcome to Your Vue.js App"/>
  <!-- <HomeComp msg="Hello Harshal"/> -->
  <!-- <ForLoop/> -->
  <Temp/>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'
// import HomeComp from './components/HomeComp.vue';
// import ForLoop from './components/ForLoop.vue';
import Temp from './components/Temp.vue';


export default {
  name: 'App',
  components: {
    HelloWorld,
    // HomeComp,
    // ForLoop
    // Demo,
    Temp
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Tushar Bhakare
  • 449
  • 1
  • 3
  • 14

10 Answers10

50

Add this to the "rules"-section at eslintrc.js if you don't want to change component names:

'vue/multi-word-component-names': 'off', 

(Taken from the response of @lifecoder above, but can't add it as a comment due to my reputation)

jory
  • 654
  • 5
  • 3
  • 5
    My rules were listed under "eslintConfig" in `package.json`, and I had to *restart* VS Code for the change to take effect – Prid Jun 02 '22 at 14:59
  • updated `package.json` and still getting the error... don't have a `eslintrc.js` file, so I don't know where this should set... – monkut Sep 15 '22 at 01:20
  • @monkut Just create it in the project's root folder (the folder where .gitignore, README.md are located). – Seangle Dec 24 '22 at 08:10
26

Your linter just tells you, that your component name should be a multi word like MyTemp instead of just Temp.

You could rename the component or disable the linting rule.

emen
  • 6,050
  • 11
  • 57
  • 94
  • How does one do that in a vue app? – AntonyMN Apr 15 '22 at 10:19
  • Right click the file name and rename it to whatever you'd like. – Dgloria Apr 27 '22 at 10:23
  • 31
    Are you seriously supposed to add meaningless words to a component that best fits as a single word? That seems like a horrible rule to be the default. – Jason Goemaat May 14 '22 at 18:10
  • 3
    @JasonGoemaat It's like that because in the future default HTML tags may be created that can conflict with how you used components in your code. But it's kinda pointless, instead just force developers to have components in PascalCase. That way Vue knows if a tag has a capital letter, it's 100% a component. Also since it's declared in the 'components' object anyway, I don't know if this rule should really exist, just overwrite the potential HTML tag and that's all. – Seangle Oct 06 '22 at 10:02
23

Add "rules": {"vue/multi-word-component-names": "off"} to eslintConfig in package.json

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Eyüp Okur
  • 231
  • 2
  • 2
7

There are several things you can do to help:

  1. To name two floods
  2. That you can add this code to your project:
{
   "vue/multi-word-component-names": ["error", {
      "ignores": []
   }]
}

Be sure to look at the full document on this site.

emen
  • 6,050
  • 11
  • 57
  • 94
1

So I also encounter the same error, All you have to do is change the name of the component from Temp to MyTemp or any other two word combination.

Here, you can also see and take the idea from the vue/multi-word-component-names Documentation, They explained things very clearly and is very helpful :-

https://eslint.vuejs.org/rules/multi-word-component-names.html

nakli_batman
  • 481
  • 8
  • 4
1

I recommend to change the name of the Component. Temp to MyTemp.

So replace every where you have Temp to MyTemp

And try by renaming the declaring part like this instead of MyTemp

<my-temp />
Mishen Thakshana
  • 143
  • 1
  • 12
  • 1
    Why would you use kebab-case and how does it help here? Kebab case is the cause that this pointless rule exists, and it's only useful if you're not using SFC. – Seangle Dec 24 '22 at 08:14
0

Just use a multiple word name, like "MyCounters", not only "Counter".

export default {
  name: "MeusContadores",
  components: {
    "app-contador": MeuContador,
  },
};
Michel Fernandes
  • 1,187
  • 9
  • 8
0

Go to vue.config.js file

const { defineConfig } = require('@vue/cli-service')
  module.exports = defineConfig({
  transpileDependencies: true,
  // Add this line of code to disable lintOnSave
  lintOnSave: false
})
Joshua
  • 9
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Ethan Jun 20 '22 at 23:50
  • 1
    This answer is potentially harmful (to the workflow). It's like disabling ESLint but not completely. Better just disable the rule. Use @Joshua's answer only after reading [this](https://cli.vuejs.org/config/#lintonsave) – Seangle Oct 06 '22 at 10:06
  • 1
    Yeah this just disables linting until you explicitly lint the project. Don't follow this answer – Seangle Dec 24 '22 at 08:13
0

In your component

Export default {
Name : '( this name )'

This name should be multi-word For example

(mytepm)
(MyTemp)
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

In <script setup> syntax the component name is inferred from the file name which should be written in PascalCase format like

TempComp.vue

or in kebab-case format :

temp-comp.vue

other format like tempComp or temp-Comp are accepted but they look bad

for more details please check rule-details

Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164