组件已定义但从未使用过 no-unused-vars

Jor*_*e12 2 vue.js vuejs2

我已经制作了一个 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>
Run Code Online (Sandbox Code Playgroud)

然后我将它导入App.vue

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

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

<style scoped>
  /* Some style  */
</style>
Run Code Online (Sandbox Code Playgroud)

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

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

Vue.config.productionTip = false

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

我收到以下错误:

 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
Run Code Online (Sandbox Code Playgroud)

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

Han*_*mos 6

您正在导入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>
Run Code Online (Sandbox Code Playgroud)