this.$axios.$get 请求后台接口数据(get请求和post请求)

安装

npm install vue-axios --save

main.js文件

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

.vue文件

test(){
        var testUrl='http://localhost:8088/activiti/doneTask';
        this.$http.get(testUrl).then(function(response){
            alert(response.data);
        }).catch(function (response) {
          alert("error");
        })
},

 


请求后台接口数据(get请求和post请求)
1.get请求

  • 不需要带参数的get请求

this.$axios.get(this.GLOBAL.host.+“后台接口地址”).then(res => {
//获取你需要用到的数据
})
  • 需要带参数的get请求

this.$axios.get(this.GLOBAL.host.+“后台接口地址”,{
    params:{            
        phone:12345678   //参数,键值对,key值:value值
        name:hh
    }
}).then(res => {
    //获取你需要用到的数据
});

2.post请求


var data = {phone:12345678,name:hh}  //定义一个data储存需要带的参数
this.$axios.post(this.GLOBAL.host+“后台接口地址”,this.$qs.stringify(data)
).then(res =>{
    //获取你需要的数据
});

// main.js文件


import axios from "axios";
import qs from 'qs';
import Global from '../static/config/global';

Vue.prototype.$axios = axios
Vue.prototype.$qs = qs;
Vue.prototype.GLOBAL = Global;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值