Nuxt.js で underscore.js を使うためのメモ。
1. vue-underscore を入れる
yarn add vue-underscore
2. プラグイン化する
/plugins/underscore.js
ファイルを作成、中身は以下3行
import Vue from 'vue' import underscore from 'vue-underscore' Vue.use(underscore)
3. nuxt.config.js で設定
さっき作ったプラグインファイルを指定しておく
plugins: [ { src: '@/plugins/underscore', ssr: false }, ],
4. 使う
mounted() { console.log(this.$_.range(10, 20)) },
以上です