Failed to compile vue.js app due to axios get request

Babr

I have this seemingly simple vue.js component which causes the app fail to compile:

<template>
<div>
  <div v-if="token"> 
    u R LOGED IN {{userid}}
  </div>
  <div v-else> 
    Token not found
  </div>


</div>

</template>

<script>
import axios from 'axios';

export default {
  name: 'AboutMe',

 created: {
    axios.get('http://127.0.0.1:3000/profile/aboutme/somejibberish'  )
    .then( res => { 
      console.log(res);

    })
    .catch( error => {  
      console.log(error);
    })
  }

}
</script>

The error that I get is:

 ERROR  Failed to compile with 1 errors                                                                             

 error  in ./src/components/AboutMe.vue?vue&type=script&lang=js&

Syntax Error: SyntaxError: /home/me/vue-myapp/src/components/AboutMe.vue: Unexpected token, expected "," (122:9)

  120 | 
  121 |   created: {
> 122 |     axios.get('http://127.0.0.1:3000/profile/aboutme/fwefwefewf'  )
      |          ^
  123 |     .then( res => { 
  124 |       console.log(res);
  125 | 


 @ ./src/components/AboutMe.vue?vue&type=script&lang=js& 1:0-222 1:238-241 1:243-462 1:243-462
 @ ./src/components/AboutMe.vue
 @ ./src/routes.js
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://192.168.1.10:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

I have used axiom in other components in the same app without any issues so have no clue what could be wrong here? How can I fix it?

thefallen

The created property needs to be a function, not an object:

import axios from 'axios';

export default {
  created() {
    axios.get(...
  }
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

axios get request Error: Request failed with status code 504

分類Dev

Vue.js Axios: unable to update page after HTTP GET request

分類Dev

Axios Vue Js:このオブジェクトの値を取得してAPIに表示する方法get request url

分類Dev

Axios createError.js:16 Uncaught (in promise) Error: Request failed with status code 400

分類Dev

sending array data with multipart/form-data post request in Axios vue.js

分類Dev

Dynamic dropdown list react axios get request

分類Dev

How to get value from Axios request?

分類Dev

Axios catch error Request failed with status code 404

分類Dev

Intercept Axios request with global JS methods

分類Dev

Async/await axios calls with Vue.js

分類Dev

Upload multiple file with vue js and axios

分類Dev

Vue.js Can't get the data out of a get request into a variable

分類Dev

Push rejected, failed to compile Python app, pythonnet: finished with status 'error'

分類Dev

How to get Params from url for Axios GET request?

分類Dev

Vue.jsアプリのどこでaxios.interceptors.request.useを呼び出すのですか?

分類Dev

Vue.js - axios is undefined when trying to store and display vue-axios response data

分類Dev

401 HTTP error on basic auth GET request from Axios to API

分類Dev

Sending Request body for GET method in AXIOS throws error

分類Dev

Vuex: Axios GET request returns undefined inside component

分類Dev

React Native axios get request path of url after redirect

分類Dev

Do SQLDatabases get closed if an App crashes due to other unhanded Exceptions?

分類Dev

Can't set property inside of Axios promise in Vue JS

分類Dev

Why does vue.js statement with axios start later?

分類Dev

Fresh project fail to compile after installing vuetify in vue.js

分類Dev

Vue.jsでAxiosを使用してgetリクエストのタイムアウトを設定する方法

分類Dev

Vue.jsのaxiosを使用してLaravelAPIにgetリクエストを送信する

分類Dev

Vue.jsのトラブル、axios.getから配列を表示できません

分類Dev

「TypeError:未定義のプロパティ 'get'を読み取れません」、Axios、Vue.JS

分類Dev

「TypeError:未定義のプロパティ 'get'を読み取れません」、Axios、Vue.JS

Related 関連記事

  1. 1

    axios get request Error: Request failed with status code 504

  2. 2

    Vue.js Axios: unable to update page after HTTP GET request

  3. 3

    Axios Vue Js:このオブジェクトの値を取得してAPIに表示する方法get request url

  4. 4

    Axios createError.js:16 Uncaught (in promise) Error: Request failed with status code 400

  5. 5

    sending array data with multipart/form-data post request in Axios vue.js

  6. 6

    Dynamic dropdown list react axios get request

  7. 7

    How to get value from Axios request?

  8. 8

    Axios catch error Request failed with status code 404

  9. 9

    Intercept Axios request with global JS methods

  10. 10

    Async/await axios calls with Vue.js

  11. 11

    Upload multiple file with vue js and axios

  12. 12

    Vue.js Can't get the data out of a get request into a variable

  13. 13

    Push rejected, failed to compile Python app, pythonnet: finished with status 'error'

  14. 14

    How to get Params from url for Axios GET request?

  15. 15

    Vue.jsアプリのどこでaxios.interceptors.request.useを呼び出すのですか?

  16. 16

    Vue.js - axios is undefined when trying to store and display vue-axios response data

  17. 17

    401 HTTP error on basic auth GET request from Axios to API

  18. 18

    Sending Request body for GET method in AXIOS throws error

  19. 19

    Vuex: Axios GET request returns undefined inside component

  20. 20

    React Native axios get request path of url after redirect

  21. 21

    Do SQLDatabases get closed if an App crashes due to other unhanded Exceptions?

  22. 22

    Can't set property inside of Axios promise in Vue JS

  23. 23

    Why does vue.js statement with axios start later?

  24. 24

    Fresh project fail to compile after installing vuetify in vue.js

  25. 25

    Vue.jsでAxiosを使用してgetリクエストのタイムアウトを設定する方法

  26. 26

    Vue.jsのaxiosを使用してLaravelAPIにgetリクエストを送信する

  27. 27

    Vue.jsのトラブル、axios.getから配列を表示できません

  28. 28

    「TypeError:未定義のプロパティ 'get'を読み取れません」、Axios、Vue.JS

  29. 29

    「TypeError:未定義のプロパティ 'get'を読み取れません」、Axios、Vue.JS

ホットタグ

アーカイブ