【エラー解決方法】Nuxt.js で「error ” is assigned a value but never used no-unused-vars」が発生したときの対処法

こんにちは、樋口です。
 
今回は、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)

ソースを実行した際に下記エラーが発生します。

error ‘testParam’ is assigned a value but never used no-unused-vars

エラー発生時の環境

エラー発生時の環境は、下記の通りです。

Vue.js
2.6.11
Nuxt.js
2.12.2

エラー解決方法

今回のエラーの原因は、使用していない変数を宣言しているためとなります。ソースを下記内容に、修正することによりエラーがなくなります。

<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>

 
これで無事、解決です。
 
 
 
 
《関連記事》

記事をシェア
MOST VIEWED ARTICLES