axiosのインストール使用と「axios is not defined」の解決方法

1662 ワード

axiosのインストール
1、npmを使う
$ npm install axios

2、bowerを使う:
$ bower install axios

3、cdnを使う:

が っているnpmは、axiosで んだ を っています.
くのチュートリアルでは、このように かれた があります.
sendGet() {
        axios.get('http://localhost:3000/info', {
            // params:{
            // 	name:'aa',
            // 	age:22
            // }
            params: this.user
          })
          .then(resp => {
            console.log(resp);
          }).catch(err => {
            console.log(err);
          })
      }

ただし、 にエラーが し、axios is not definedが されます.
axios          ‘axios is not defined’_ 1

メールでjsに く
import axios from 'axios';
Vue.prototype.$axios = axios;

そして のコードを
sendGet() {
        this.$axios.get('http://localhost:3000/info', {//   axios.get   this.$axios.get
            // params:{
            // 	name:'aa',
            // 	age:22
            // }
            params: this.user
          })
          .then(resp => {
            console.log(resp);
          }).catch(err => {
            console.log(err);
          })
      },

これで「axios is not defined」のエラーを ・・
 
もし が いた けがあなたを けたと ったら、 にいいねをしてください.