nuxt - 踩坑(一)安装lodash

  • 安装lodash

     yarn install lodash
    
  • 作为第三方插件引入

    //  plugins/lodash.js
    import _ from 'lodash'
    import Vue from 'vue'
    Vue.prototype.$lodash = _
    /* export default ({ app }, inject) => {
     inject('lodash', _)
    } */
    //这边只能vue页面使用
    
  • 若需要js文件里使用_ ,可在nuxt.config.js里配置

     build: {
        plugins: [
           new webpack.ProvidePlugin({
            _: 'lodash'
         })
       ]
    }
    
5375657-9881c08289984181.png
赞赞哇.png

猜你喜欢

转载自blog.csdn.net/weixin_33912638/article/details/86971177
今日推荐