After vue2 upgrades to vue3, axios alway sends params with text/plain and the value is [object Object] ? #11994
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I upgraded vue2 to vue3, install [email protected] and installed same version of @vue/compat, and replace vue-template-compiler (if present) with @vue/compiler-sfc, folllowed by the document: https://v3-migration.vuejs.org/migration-build.html.
And create a global axios instance:
And set global instance with vue3 way:
![image](https://private-user-images.githubusercontent.com/5260711/369580015-7a9455b0-310e-437e-a65c-7c870baeac17.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NDI3NTksIm5iZiI6MTczOTQ0MjQ1OSwicGF0aCI6Ii81MjYwNzExLzM2OTU4MDAxNS03YTk0NTViMC0zMTBlLTQzN2UtYTY1Yy03Yzg3MGJhZWFjMTcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTNUMTAyNzM5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTU2MzczZWNlOGM0NDAzNjVmNWY2MWRlZTBlMGMxZWQwYjZhOGNhN2RjM2RlNDBmNzFiOTgxYjRmYzM1OGViMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.Hdab5GmFSZ7Bai3260ZGKAH56j9mzIuhsrGuCuff0Gs)
Webpack config is
When I use the axios api get like this :
The axios always sends params with text/plain (Even though I set content-type with "application/json" in headers) and the url is like this, the value is [object Object]:
![image](https://private-user-images.githubusercontent.com/5260711/369579453-072d0e82-aa44-43f1-b1ba-4a1a30810876.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NDI3NTksIm5iZiI6MTczOTQ0MjQ1OSwicGF0aCI6Ii81MjYwNzExLzM2OTU3OTQ1My0wNzJkMGU4Mi1hYTQ0LTQzZjEtYjFiYS00YTFhMzA4MTA4NzYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTNUMTAyNzM5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MmQ5ZjFhYWFkYjZjZmM5MmQ0NmEyYjkyOTUwOTY2YzU0NWVhMTc0MzgzOTFiM2Y1OTZkNjgxYmE3NWFiYmE2OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.81uRigppYIrkpEA09CmyDCI60oQKW0OuXKHrmJS5Jlg)
I guess there is something wrong about the encoding for vue compiler, or missing some config, but I have no idea.
Does someone know how to fix it ?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions