【问题标题】:Component is defined but never used no-unused-vars组件已定义但从未使用 no-unused-vars
【发布时间】:2020-05-26 17:13:22
【问题描述】:

我已经制作了一个 Vue CLI 项目,然后开始制作我的项目。

我制作了以下名为Navigation.vue的组件:

<template>
  <nav>
    <div class="nav_container">
      <a href="https://www.metrici.ro/" target="_blank" class="logo"></a>
      <ul>
        <li><router-link to="/home">Home</router-link></li>
        <li class="dropdown">
          <a class="touch"
            >Network Settings <i class="fas fa-angle-down"></i
            ><i class="fas fa-angle-up"></i
          ></a>
          <div class="dropdown-content">
            <router-link to="/dhcpIP">DHCP IP</router-link>
            <router-link to="/staticIP">Static IP</router-link>
          </div>
        </li>
        <!-- <li><router-link to="/files">Import/Export Files</router-link></li> -->
        <li><router-link to="/update">Update</router-link></li>
      </ul>
    </div>
  </nav>
</template>

<script>
export default {
    name: 'Navigation',
}
</script>
<style scoped>
/* Some style  */
</style>

然后我把它导入到App.vue:

<template>
  <div id="app">
    <Navigation />
    <router-view />
  </div>
</template>

<script>
  import Navigation from "./components/Navigation.vue";
</script>

<style scoped>
  /* Some style  */
</style>

最后我有main.js,我没有修改:

import App from './App.vue'
import router from './router'

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

我收到以下错误:

 ERROR  Failed to compile with 1 errors                                                                                    8:10:25 PM
 error  in ./src/App.vue

Module Error (from ./node_modules/eslint-loader/index.js):

\App.vue
  9:8  error  'Navigation' is defined but never used  no-unused-vars

该组件已明确使用,但我收到该错误。我不明白为什么。

【问题讨论】:

  • 您没有使用您正在导入的Navigation 变量。您需要将其用作组件。更多细节在这里:vuejs.org/v2/guide/…

标签: vue.js vuejs2


【解决方案1】:

您正在导入Navigation,但从未在脚本中使用它,将其声明为组件:

<template>
  <div id="app">
    <Navigation />
    <router-view />
  </div>
</template>

<script>
import Navigation from "./components/Navigation.vue";

export default {
  components: {
    Navigation 
  },
}
</script>
<style scoped>
/* Some style  */
</style>

【讨论】:

  • 它就在我面前。我不知道为什么,但是在没有名字的情况下导出App.js 感觉很奇怪。
  • @Jorje12 您是否在要导入的同一文件上使用``?
  • 我写的是component而不是components。它工作得很好。谢谢。
猜你喜欢
  • 2020-04-21
  • 2022-06-20
  • 2017-01-15
  • 1970-01-01
  • 1970-01-01
  • 2017-03-16
  • 2020-07-04
  • 2020-04-06
  • 1970-01-01
相关资源
最近更新 更多