vue中使用vconsole 当切换路由时报错,求帮忙

vue main.js 中引入


 import VConsole from 'vconsole'
let option ={
  maxLogNumber:1000
}
var VConsole = new Vconsole(option);

组件正常显示并且可以正常使用但是每次切换路由都会报错
main.js [Vue warn]: Property or method "toJSON" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

阅读 7.3k
4 个回答

是不是哪里打印了复杂的对象,试试注释掉代码里的console

使用了 vconsole 后,如果打印了复杂的对象会出现这种问题,比如说下面这种情况:

router.beforeEach((to, from, next) => {
  console.log(to) 
  // or
  console.log(from)
})

在main.js中使用 就ok
import Vconsole from ‘vconsole‘
let vConsole = new Vconsole()

你自己看报错信息,[Property or method "toJSON" is not defined on the instance] 说明在切换路由时肯定有个地方非法引用了toJSON这个方法。
既然你在main.js引用了vconsole,组件正常显示并且可以正常使用,说明你的引用没有问题。你应该去你的代码找问题

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题