简体   繁体   English

在 Nuxt.js 中使用 vue-underscore

[英]Using vue-underscore in Nuxt.js

I'm currently reworking an application that I was making in VueJS for Nuxt, however I get an error missing stack frames that I can't find much about – I'm trying to use vue-underscore and while previously in VueJS this worked fine, I'm now having this missing stack frames error message appear.我目前正在重新编写我在 VueJS 中为 Nuxt 制作的应用程序,但是我得到一个错误,缺少堆栈帧,我找不到太多关于 - 我正在尝试使用vue-underscore ,而之前在 VueJS 中这工作正常,我现在有这个丢失的堆栈帧错误消息出现。

In a vue-underscore.js file I setup underscore like this:vue-underscore.js文件中,我像这样设置下划线:

import Vue from 'vue'
import underscore from 'vue-underscore'

Vue.use(underscore)

I import {_} like this in my component:我在我的组件中像这样导入{_}

import {_} from 'vue-underscore';

Error message here:这里的错误信息:

"use strict";
    __webpack_require__.r(__webpack_exports__);
    /* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = 
    __webpack_require__(/*! vue */ "vue");
    /* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0___default = 
    /*#__PURE__*/__webpack_require__.n(vue__WEBPACK_IMPORTED_MODULE_0__);
    /* harmony import */ var vue_underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! vue-underscore */ "vue-underscore");
/* harmony import */ var vue_underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(vue_underscore__WEBPACK_IMPORTED_MODULE_1__);
 vue__WEBPACK_IMPORTED_MODULE_0___default.a.use(vue_underscore__WEBPACK_IMPORTED_MODULE_1___default.a); 

Any help gratefully received.感激地收到任何帮助。

I had the same problem.我有同样的问题。 We both were badly using it!我们俩都用得不好!

Let's summarize.让我们总结一下。

  1. Add the repo添加回购

npm install vue-underscore

OR或者

yarn add vue-underscore

  1. Create a file named plugins/underscore.js创建一个名为 plugins/underscore.js 的文件
import Vue from 'vue'
import underscore from 'vue-underscore'
Vue.use(underscore)
  1. Add it to the nuxtconfig.js file将其添加到 nuxtconfig.js 文件中

plugins: [{ src: '~/plugins/underscore', ssr: false }]

  1. Use it用它
<script>
export default {
  name: 'MyComponent',
  mounted() {
    console.log(this.$_.range(2000, 2020))
  }
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM