Nuxt + vConsole : TypeError: Cannot call a class as a function

问题描述

Nuxt 引用 vConsole 异常 : Uncaught TypeError: Cannot call a class as a function,错误信息如下:

vconsole.min.js?3a34:10 Uncaught TypeError: Cannot call a class as a function
    at eval (vconsole.min.js?3a34:10)
    at e (vconsole.min.js?3a34:10)
    at Function.Vue.use (vue.runtime.esm.js?2b0e:5109)
    at eval (vconsole.js?f5c4:4)
    at Module../plugins/vconsole.js (app.js:599)
    at __webpack_require__ (runtime.js:854)
    at fn (runtime.js:151)
    at eval (index.js:49)
    at Module../.nuxt/index.js (app.js:227)
    at __webpack_require__ (runtime.js:854)

截图

image.png

相关代码

  • nuxt.config.js
export default {
  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
    '@/plugins/vant',
    { src: '@/plugins/vconsole', ssr: false }
  ],
}
  • plugins\vconsole.js
import Vue from 'vue'
import vConsole from 'vconsole'

Vue.use(vConsole)

你期待的结果是什么?

在nuxt中正常的引用并使用vConsole

回答:

修改 plugins\vconsole.js

import VConsole from 'vconsole'
var result = new VConsole()

console.log(result)
console.log(result.version)

暂无评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注