简体   繁体   English

如何解决“错误'Vote'已定义但从未使用(no-unused-vars)”的问题?

[英]How to solve the problem “error 'Vote' is defined but never used ( no-unused-vars)”?

can you help me?.I'm getting error when i will to import file Vote.And errors that appear like 'Vote' is defined but never used ( no-unused-vars).I tried to rename the Vote file and he result are nill.你能帮我吗?。当我要导入文件投票时出现错误。并且看起来像“投票”的错误已定义但从未使用过(no-unused-vars)。我试图重命名投票文件,他的结果是零。

Home.vue
import Vote from "@/components/Vote.vue";
export default {
name: "Home",
components: { Vote }
};

Vote.vue
<script> // @ is an alias to /src //import HelloWorld from "@/components/HelloWorld.vue";
export default {
name: "Vote",
components: {},
data: function(){
return{ emoticons : ['calon-1','calon-2','calon-3','calon-4'] }

  }
};

sounds like a linting notice.听起来像一个棉绒通知。 https://eslint.org/docs/rules/no-unused-vars . https://eslint.org/docs/rules/no-unused-vars

To solve this you should use your <Vote/> component somewhere in your Home.vue HTML.要解决这个问题,您应该在Home.vue HTML 中的某处使用<Vote/>组件。

I am pretty sure that your linting rules want to have a component registration with a component use inside your HTML.我很确定您的 linting 规则希望在 HTML 中使用组件进行组件注册。 That means a simple import wont solve this, because a import is not a "using".这意味着简单的导入不会解决这个问题,因为导入不是“使用”。 Do you work with the Vue-CLI?你使用 Vue-CLI 吗? if yes, which lint rule set do you use?如果是,您使用哪个 lint 规则集? you can disable not needed rules in your Webpack config.您可以在 Webpack 配置中禁用不需要的规则。

And to find your webpack.config.js we need to know which kind of settings you did in your setup CLI process.为了找到您的webpack.config.js ,我们需要知道您在设置 CLI 过程中进行了哪些设置。

Check your: package.json file in your root directory, is there something like esLint except the npm dependencies in there?检查您的: package.json文件在您的根目录中,除了 npm 依赖项之外,是否有类似esLint的东西?

if not then you can create a new file in your root called .eslintrc.js and inside you paste this:如果没有,那么您可以在根目录中创建一个名为.eslintrc.js的新文件,然后在其中粘贴:

module.exports = {
  root: true,
  rules: {
    "no-unused-vars": "off"
  },
};


this will fix your problem but imho you should not disable such rules, they help you to clean code这将解决您的问题,但恕我直言,您不应该禁用此类规则,它们可以帮助您清理代码

Vote is a variable(or class). Vote是一个变量(或类)。 you defined it as a string here.您在此处将其定义为字符串。 Please change请更换

name: "Vote"

to

name: Vote

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 组件已定义但从未使用 reactjs 中的 no-unused-vars 错误警告 - component is defined but never used no-unused-vars error warning in reactjs 定义了“ stringValues”,但从未使用过no-unused-vars - “stringValues” is defined but never used no-unused-vars 定义了“标头”,但从未使用过未使用的变量 - 'Header' is defined but never used no-unused-vars &#39;Home&#39; 已定义但从未使用 no-unused-vars&quot;.* - 'Home' is defined but never used no-unused-vars".* &#39;UserInput&#39; 已定义但从未使用过 no-unused-vars &#39;UserOutput&#39; 已定义但从未使用过 no-unused-vars - 'UserInput' is defined but never used no-unused-vars 'UserOutput' is defined but never used no-unused-vars Eslint with Vue 给出 function 已定义但从未使用过 no-unused-vars - Eslint with Vue gives function is defined but never used no-unused-vars @typescript-eslint/eslint-plugin 错误:定义了“路由”但从未使用过(no-unused-vars) - @typescript-eslint/eslint-plugin error: 'Route' is defined but never used (no-unused-vars) 11:5 错误“路由器”被分配了一个值,但从未使用过 no-unused-vars - 11:5 error 'router' is assigned a value but never used no-unused-vars src\\App.js &#39;nav&#39; 已定义但从未使用过 no-unused-vars - src\App.js 'nav' is defined but never used no-unused-vars &#39;inStock&#39; 被赋值但从未使用过 no-unused-vars - 'inStock' is assigned a value but never used no-unused-vars
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM