Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw Uncaught TypeError when vConsole.destroy() #587

Open
heyzqq opened this issue Dec 1, 2022 · 6 comments
Open

Throw Uncaught TypeError when vConsole.destroy() #587

heyzqq opened this issue Dec 1, 2022 · 6 comments
Labels
Details wanted Need more details

Comments

@heyzqq
Copy link

heyzqq commented Dec 1, 2022

vConsole Version:
V3.15.0

Project:
RuoYi-Vue

销毁 VConsole 时会报错:

import VConsole from 'vconsole'

var __vconsole

export default {
  open() {
    __vconsole = new VConsole()
  },
  close() {
    __vconsole.destroy()
    __vconsole = null
  },
  toggle() {
    if (__vconsole == null) {
      this.open()
    } else {
      this.close()
    }
  },
}

以上的操作放到了 Vue.prototype.$vconsole 中,直接调用 this.toggle(),能正常打开关闭,但是关闭后,会报如下错误:

image

@heyzqq
Copy link
Author

heyzqq commented Dec 1, 2022

Details:

image

@heyzqq
Copy link
Author

heyzqq commented Dec 1, 2022

看到错误信息,破案了,输出 vConsole 会报错:

console.log('close vconsole1', __vconsole)

这是变量不能读取吗,是有什么和 console.log 冲突了呢?

@Soonze
Copy link

Soonze commented Apr 26, 2023

遇到了同样问题,销毁后有报错。我是在插件on('ready')回调中进行的销毁

image

@terwer
Copy link

terwer commented May 23, 2023

+1销毁报错,没有其他任何多余的代码

image

export const useConsole = async () => {
  const vConsole = new VConsole()

  // call `console` methods as usual
  console.log("vConsole loaded")

  // remove it when you finish debugging
  if (!isDev) {
    vConsole.destroy()
  }
}

@Maizify
Copy link
Collaborator

Maizify commented May 24, 2023

@terwer 代码片段是完整的代码吗?在 ready 事件后再调用 destroy() 试试看?

@Maizify Maizify added the Details wanted Need more details label May 24, 2023
@terwer
Copy link

terwer commented May 24, 2023

@Maizify
我是 Vue3 项目,在 setup 里面 vue 的 onMounted 钩子里面里面初始化,然后销毁。

我有个复现链接 https://xul67b-5173.csb.app/
直接打开控制台能看到错误

源码:

https://codesandbox.io/p/sandbox/loving-davinci-xul67b?file=%2Fsrc%2Fcomposables%2FuseConsole.ts%3A4%2C35

https://codesandbox.io/p/sandbox/loving-davinci-xul67b?file=%2Fsrc%2FApp.vue

Vue 貌似没有 ready 事件,只有 onMounted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Details wanted Need more details
Projects
None yet
Development

No branches or pull requests

4 participants