“道具”被分配了一个值但从未使用过 no-unused-vars vue3
P粉810050669
P粉810050669 2023-08-25 17:00:46
[Vue.js讨论组]
<p>我在我的 vue 组件文件上使用。我的组件代码:</p> <pre class="brush:php;toolbar:false;">&lt;template&gt; &lt;router-link :to=&quot;{ name: routerName }&quot; type=&quot;is-primary&quot; class=&quot;inline-flex justify-center py-2 px-3 mb-3 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; class=&quot;h-5 w-5&quot; fill=&quot;none&quot; viewBox=&quot;0 0 24 24&quot; stroke=&quot;currentColor&quot;&gt; &lt;path stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; stroke-width=&quot;2&quot; d=&quot;M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z&quot; /&gt; &lt;/svg&gt;&amp;nbsp;Cancel &lt;/router-link&gt; &lt;/template&gt; &lt;script setup&gt; const props = defineProps({ routerName: { type: String, required: true } }) &lt;/script&gt;</pre> <p>但其返回eslint错误<code>'props'被赋值但从未使用过 no-unused-vars</code></p> <p>我已经在我的 package.json 上添加了如下规则:</p> <pre class="brush:php;toolbar:false;">&quot;extends&quot;: [ &quot;plugin:vue/vue3-essential&quot;, &quot;eslint:recommended&quot; ], &quot;parserOptions&quot;: { &quot;parser&quot;: &quot;@babel/eslint-parser&quot; }, &quot;rules&quot;: { &quot;vue/script-setup-uses-vars&quot;: &quot;error&quot;, &quot;vue/multi-word-component-names&quot;: &quot;off&quot; }</pre> <p>仍然错误。我的开发依赖:</p> <pre class="brush:php;toolbar:false;">&quot;devDependencies&quot;: { &quot;@babel/core&quot;: &quot;^7.12.16&quot;, &quot;@babel/eslint-parser&quot;: &quot;^7.12.16&quot;, &quot;@vue/cli-plugin-babel&quot;: &quot;~5.0.0&quot;, &quot;@vue/cli-plugin-eslint&quot;: &quot;~5.0.0&quot;, &quot;@vue/cli-service&quot;: &quot;~5.0.0&quot;, &quot;eslint&quot;: &quot;^7.32.0&quot;, &quot;eslint-plugin-vue&quot;: &quot;^8.0.3&quot; },</pre></p>
P粉810050669
P粉810050669

全部回复(1)
P粉298305266

您收到错误是因为(正如错误指出的那样)您从不使用 props。您可以删除 const props = 或(我建议)将 "no-unused-vars": "warn" 添加到 package.json 中的规则中。 p>

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号