Skip to content
New issue

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

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

Already on GitHub? # to your account

Why is response.data.constructor !== Object #565

Open
LucidityDesign opened this issue Feb 22, 2022 · 1 comment
Open

Why is response.data.constructor !== Object #565

LucidityDesign opened this issue Feb 22, 2022 · 1 comment

Comments

@LucidityDesign
Copy link

LucidityDesign commented Feb 22, 2022

anyobject.constructor === Object is a popular method to check if a variable is an object (e.g. see here: https://stackoverflow.com/a/16608074/1301058)

For the server-side response data from $axios.get this doesn't work because response.data.constructor === Object returns false.

Steps to reproduce:

  1. git clone git@github.com:LucidityDesign/axios-module.git
  2. yarn install
  3. yarn dev
  4. open localhost:3000/ssr
  5. console logs response type false
  6. see https://github.com/LucidityDesign/axios-module/blob/main/test/fixture/pages/ssr.vue#L17

Expected behaviour:

response.data.constructor === Object
// => true
@LucidityDesign
Copy link
Author

So I tried to debug this phenomenon:
After axios is transforming the response response.data.constructor === Object is true.
Due to the resolving of promises I lose track of the variable, but as soon as they appear in this module (e.g. here) response.data.constructor === Object is false.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant