axios

npm安装

npm install --save axios vue-axios

安装完之后,在你的main.js文件里配置,加上这两句就好

import axios from 'axios'
Vue.prototype.$http = axios

然后你读取接口数据的时候,直接就可以这样写,这个跟resource一个样,我那个下面的op,uin之类的都是要传的参数。

this.$http.post(localStorage.getItem("addUrl")+'/skynet_sync/btsp', {
                            "op": "update_card_num",
                            "uin": uin,
                            "protypeId": index,            
                            "cardNumber": parseInt(v)
                        })
                      .then(response=> {
                        //如果接口走成功就执行这里

                      }).catch(function (error) {
                        //接口失败,也就是state不是200的时候,走这里
                      });

好了,搞定!

原文地址:https://www.cnblogs.com/AlbertP/p/10805033.html