關於vue3.0使用axios報錯問題

vue-cli3.0使用axios的時候出現錯誤,記錄一下

報錯信息:

Uncaught TypeError: Cannot set property $axios of #<Vue> which has only a getter
at eval (main.js?56d7:12)
at Module../src/main.js (app.js:11102)
at __webpack_require__ (app.js:724)
at fn (app.js:101)
at Object.0 (app.js:11283)
at __webpack_require__ (app.js:724)
at app.js:791
at app.js:794

vue-cli3.0安裝插件的時候要註意區分vue-cli2.0的命令

安裝:

//vue-cli2.0命令
$ npm install axios
//vue-cli3.0命令
$ npm add axios

使用:

1.首先在main.js裡邊把axios實例掛載到Vue原型上
  坑點: 命名的時候不能使用"axios"這個字段
import axios from 'axios'
Vue.prototype.$ajax = axios
2.在需要發送請求的地方使用"$ajax"
this.axioss.get('/api/seller')
        .then(function(res){
            console.log(res);
            this.seller = res.data;
        })
        .catch(function(error){
            console.log(error);
        })

到此這篇關於vue3.0使用axios報錯問題記錄的文章就介紹到這瞭,更多相關vue3.0使用axios報錯內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: