お知らせ
2023.12.5(Tue)
目次
こんにちは、樋口です。
今回は、Nuxt.jsの「error ” is assigned a value but never used no-unused-vars」を解決する方法をご紹介します。
今回のエラーが発生するコードは下記ソースとなります。
<template>
<div class="samaple__conntents">
<div style="margin-top: 20px;">
<h1>Font awesome</h1>
</div>
</div>
</template>
<script>
export default {
data() {
return {
count: 0,
}
},
computed: {
test() {
const testParam = 100
return 0
},
},
}
</script>
ソースを実行した際に下記エラーが発生します。
error ‘testParam’ is assigned a value but never used no-unused-vars

エラー発生時の環境は、下記の通りです。
今回のエラーの原因は、使用していない変数を宣言しているためとなります。ソースを下記内容に、修正することによりエラーがなくなります。
<template>
<div class="samaple__conntents">
<div style="margin-top: 20px;">
<h1>Font awesome</h1>
</div>
</div>
</template>
<script>
export default {
data() {
return {
count: 0,
}
},
computed: {
test() {
const testParam = 100 ← 不要変数である、この部分を削除します
return 0
},
},
}
</script><template>
<div class="samaple__conntents">
<div style="margin-top: 20px;">
<h1>Font awesome</h1>
</div>
</div>
</template>
<script>
export default {
data() {
return {
count: 0,
}
},
computed: {
test() {
return 0
},
},
}
</script>