vue中使用axios

作者: 井皮 | 来源:发表于2018-11-21 12:39 被阅读0次

一.axios安装与引用

1.axios的安装

npm  install  axios  --save-dev

2.axios的引用

import axios from 'axios';

二.axios使用

1.GET方法

    axios({

                method:'get',

                url:resquestURL,

                data:params

            }).then(function(res){

              console.log(res.data);

            }.bind(this)).catch(function(err){

              console.log(err);

          })

2.POST方法

axios-post请求需要将提交data转换成键值对的数据格式,借助qs模块(需npm下载)封装提交的data数据

import Qs from 'qs' 

      var params = {

            'api':'json',

            'isSubmit':'1'

        };

      axios({

                method:'post',

                url:resquestURL,

                data:Qs.stringify(params),

                header:{

                  "Content-type":"application/x-www-form-urlencoded"

                }

            }).then(function(res){

              console.log(res.data);

            }.bind(this)).catch(function(err){

              console.log(err);

          })

相关文章

网友评论

    本文标题:vue中使用axios

    本文链接:https://www.haomeiwen.com/subject/imoqqqtx.html