uniapp发起请求的方法:1、使用【uniapp.request({})】方法;2、使用【this.$axios({})】方法,代码为【this.$axios({method: 'get',url: this.$api+ '/Test】。

本教程操作环境:windows7系统、uni-app2.5.1版本、thinkpad t480电脑。
推荐(免费):uni-app开发教程
uniapp发起请求的方法:
1、使用uniapp.request({})方法
uni.request({
uni.request({
url: this.$api+'/Test/student/test',
header: {
'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
},
//请求成功后返回
success: (res) => {
// 请求成功之后将数据给Info
if(res.statusCode===200)
{
self.Info = res.data;
}
}
});2、使用this.$axios({})方法
自从百度屏蔽淘宝客网站、淘宝抛弃淘宝客之后,个人站长集体陷入了恐慌之中。此时,什么值得买网的异军突起引起了广大个人站长的极大关注。做一个什么值得买一样的导购网站成了众多个人站长的一致心愿! TP-COUPON 导购系统 即是让个人站长实现此心愿的绝佳选择! 欢迎个人站长选用。V1.1版 更新记录:1.修正请求时查询淘宝店铺错误的bug2.删除一些无用的代码
this.$axios({
method: 'get',
url: this.$api + '/Test/student/test'
// data: {
// userName: 'Lan',
// password: '123'
// },
})
.then(function(res) {
if (res.data.code === 1234) {
self.Info = res.data
}
})
.catch(function(error) {
console.log(error.statusCode)
})this.a p i , t h i s . api,this.api,this.axios要在main.js当中注册为全局变量
Vue.prototype.$api='http://192.168.2.114:8099' Vue.prototype.$axios=axios
完整示例代码:
用户名: {{ Info }}
相关免费学习推荐:编程视频









