[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.
Vue Router 路由对象的 from 和to 属性需要做拷贝处理,例如: to 属性可以这样 JSON.parse(JSON.stringify(to)) 直接拷贝;另外 from 属性比较特殊(疑似因为 from.name 的声明和赋值类型不一致)则需要遍历拷贝,其中 from.matched 属性更复杂,建议不要输出,或者做深拷贝处理;
function vueRouteObjectCopy (route: Route): Route {
let _route: any = {}
for (let i in route) {
if (typeof route[i] === 'object') {
if (i === 'matched') {
_route[i] = [] // 'from.matched' is circular objects, need deep copying, recommended not to print this property
} else {
_route[i] = Object.assign({}, route[i])
}
} else {
_route[i] = route[i] || ''
}
}
return _route
}
问题描述:
原因:
解决办法:
参考:https://github.com/Tencent/vConsole/issues/152