登录 主页

vue3 组件命名

2023-11-14 02:37PM

如果你文件中的组件命名为:Background

服务器的日志会一直报错说:

 WAIT  Compiling...                                                                                                                                                                                      2:28:28 PM

Compiling...


 ERROR  Failed to compile with 1 error                                                                                                                                                                   2:28:28 PM

[eslint] 
/home/meiyi/workspace/yunkeanxin_1_front/src/App.vue
  32:9  error  Component name "Background" should always be multi-word  vue/multi-word-component-names

✖ 1 problem (1 error, 0 warnings)


You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
ERROR in [eslint] 
/home/meiyi/workspace/yunkeanxin_1_front/src/App.vue
  32:9  error  Component name "Background" should always be multi-word  vue/multi-word-component-names

✖ 1 problem (1 error, 0 warnings)


webpack compiled with 1 error

为了解决这个问题,你可以通过在组件名称中添加连字符或使用大驼峰命名法(PascalCase)来满足ESLint的要求。

有两个解决方法:

1. 使用连字符命名法(kebab-case):

<template>
  <div id="background">
    <!-- 组件内容 -->
  </div>
</template>

<script>
export default {
  name: 'background-component',
  // 组件的其他选项和代码
}
</script>

<style>
/* 样式规则 */
</style>

 2. 使用大驼峰命名法(PascalCase):

<template>
  <div id="background">
    <!-- 组件内容 -->
  </div>
</template>

<script>
export default {
  name: 'BackgroundComponent',
  // 组件的其他选项和代码
}
</script>

<style>
/* 样式规则 */
</style>

修改完之后,再查看服务器日志,就发现问题已经解决了。

 WAIT  Compiling...                                                                                                                                                                                      2:35:36 PM

Compiling...


 DONE  Compiled successfully in 265ms                                                                                                                                                                    2:35:36 PM


  App running at:
  - Local:   http://localhost:8080/ 
  - Network: http://192.168.10.4:8080/ 

返回>>

登录

请登录后再发表评论。

评论列表:

目前还没有人发表评论