Nuxt.jsでAxiosを使う方法をメモ
インストール
npm install @nuxtjs/axios --save
nuxt.config.js
modules: [ "@nuxtjs/axios", ],
nuxt.config.jsのmodulesに@nuxtjs/axiosを追加することで使えるようになります。
axiosを使う
index.vue
methods:{ test:function(){ this.$axios.$get(url) .then(function(responce){ console.log(responce) }) .catch(function(error){ console.log(error) }) } }
上のコードでtestを発火させるとレスポンスの内容がコンソールに出力されます。
エラーが発生した場合はcatchの中の関数のerrorに発生したエラーが入ります。
ビスケットを送る0
コメント