30g月流量网站,wordpress 商城,辽宁网站建设专业学校,电商网站图片uni.request(OBJECT)
发起网络请求
具体参数可查看官方文档uni-app data:请求的参数; header#xff1a;设置请求的 header#xff0c;header 中不能设置 Referer#xff1b; method#xff1a;请求方法#xff1b; timeout#xff1a;超时时间#xff0c;单位 ms header设置请求的 headerheader 中不能设置 Referer method请求方法 timeout超时时间单位 ms默认60000 dataType如果设为 json会对返回的数据进行一次 JSON.parse非 json 不会进行 JSON.parse .... 免费测试api接口https://jsonplaceholder.typicode.com/
第一种
template/templatescript setupfunction request(){uni.request({url:https://jsonplaceholder.typicode.com/posts, //开发者服务器接口地址method:post, //请求方法success:res{ //收到开发者服务器成功返回的回调函数console.log(res);}})}request();/scriptstyle langscss scoped/style第二种
template/templatescript setupfunction request(){uni.request({url:https://jsonplaceholder.typicode.com/posts}).then(res{arrs.valueres.data})}request();/scriptstyle langscss scoped/style第三种 异步同步化
template/templatescript setupasync function request(){let res await uni.request({url:https://jsonplaceholder.typicode.com/posts})arrs.valueres.data}request();/scriptstyle langscss scoped/style示例
templateview classout v-foritem in arrsview classtitle{{item.title}}/viewview classcontent{{item.body}}/view/view
/templatescript setuplet arrs ref();function request(){uni.request({url:https://jsonplaceholder.typicode.com/posts}).then(res{arrs.valueres.data})}request();
/scriptstyle langscss scoped.out{padding: 30rpx;.title{font-size: 40rpx;}.content{margin: 15rpx 0;border-bottom: 1px solid #696969;color: #696969;}}
/style注ref 没有使用 import { ref } from vue; 导入是因为下载了插件具体可查看博客没有下载的需常规导入 运行结果