Stringify Vue instance
See original GitHub issueVersion
2.6.10
Reproduction link
https://codesandbox.io/s/vue-stringify-instance-2h78n
Steps to reproduce
Open the link, the error is reproduced right away as the code tries to serliaze the Vue instance.
What is expected?
Being able to serlialize the Vue instance.
What is actually happening?
Is not possible as the Vue prototype is missing the toJSON method.
The code is using telejson
as the stringify library in order to remove circular references. Is the same utility used by Storybook 5 which will rise those errors in diferent scenarios, as for example when using the Action addon and passing as argument a Vue instance.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Vue stringify instance - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >Vue.js JSON Stringify - Method JavaScript | VueJS Example
We can use native JavaScript JSON stringify() method to convert json object to json string. Here in this tutorial, we are going to...
Read more >Vue data not available until JSON.stringify() is called
After working on the problem with a friend, I found the underlying issue being a JavaScript-specific one involving Vue's reactive nature.
Read more >Strange behavior w/ JSON.stringify Vue 3 - Get Help
My component parses URL parameters to use in a fetch call. When I print the payload inside the fetch function, the object is...
Read more >How To Use JSON.parse() and JSON.stringify() - DigitalOcean
parse() takes a JSON string and transforms it into a JavaScript object. let userStr = '{"name":"Sammy","email":"sammy@example.com" ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This can be implemented in userland, I’m sure there’s uses for this, but most users won’t need to use this.
This would be better implemented as a plugin or library
You can’t really serialise functions (computed, methods etc), VUE relies on them to work.
If you need to serialise your vue app, you may be doing something wrong. Data can be serialised, and you can have a method for that, which can integrate with your API, but it’s not easily possible to serialise a vue instance, there would be too many edge cases.