Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

$http.get(...).text is not a function #86

Closed
lcherone opened this issue Dec 22, 2019 · 5 comments
Closed

$http.get(...).text is not a function #86

lcherone opened this issue Dec 22, 2019 · 5 comments

Comments

@lcherone
Copy link

lcherone commented Dec 22, 2019

I'm getting the above error using code directly taken from the example in docs:

https://http.nuxtjs.org/guide/usage.html#using-in-asyncdata

 "dependencies": {
    "@nuxt/http": "^0.3.8",
<template>
  <pre>{{ ip }}</pre>
</template>

<script>
export default {
  async asyncData({ $http }) {
    const ip = await $http.get('http://icanhazip.com').text()
    return { ip }
  }
};
</script>

browser

screenshot-localhost_3000-2019 12 22-00_15_20

console

 ERROR  $http.get(...).text is not a function                                                      00:10:30

  at asyncData (about.vue:16:0)
  at promisify (.nuxt/utils.js:245:0)
  at Promise.all.Components.map.Component (.nuxt/server.js:215:0)
  at Array.map (<anonymous>)
  at module.exports../.nuxt/server.js.__webpack_exports__.default (.nuxt/server.js:210:0)
@ghost ghost closed this as completed Dec 22, 2019
@ghost
Copy link

ghost commented Dec 22, 2019

This issue as been imported as question since it does not respect http issue template. Only bug reports and feature requests stays open to reduce maintainers workload.
If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically.
Your question is available at https://cmty.app/nuxt/http/issues/c20.

@ghost ghost added the cmty:question label Dec 22, 2019
@lcherone
Copy link
Author

lcherone commented Dec 22, 2019

bot closed it, ill leave it with you..

@lcherone
Copy link
Author

lcherone commented Dec 22, 2019

additionally, the response object looks like:

Response 
  body: ReadableStream
    locked: false
    __proto__: ReadableStream
  bodyUsed: false
  headers: Headers
    __proto__: Headers
  ok: true
  redirected: false
  status: 200
  statusText: "OK"
  type: "cors"
  url: "http://icanhazip.com/"
  __proto__: Response

network all good and shows content (ip).. also the same error if done outside of asyncData as a normal method and called in mounted.. maybe I'm missing something obvious

@jukbot
Copy link
Contributor

jukbot commented Apr 29, 2020

Just FYI for other who got this issue.
It seems that the document is missing response promise chain, so it should be

const requestData = await $http.get('http://icanhazip.com')
const ip = await requestData.text()
return { ip }

@lcherone
Copy link
Author

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants