当前位置:网站首页>Uni app third party package configuration network request
Uni app third party package configuration network request
2022-07-06 07:06:00 【Front end childe Jia】
Due to the limitation of the platform , Not supported in applet projects axios, And the original wx.request()
API The function is relatively simple , Global customization functions such as interceptors are not supported . therefore , It is suggested that uni-app Project use @escook/request-miniprogram
Third party packet initiates network data request .
Please refer to @escook/request-miniprogram Official installation documentation 、 To configure 、 Use
Official documents :https://www.npmjs.com/package/@escook/request-miniprogram
1. initialization npm package
npm init -y Initialize at project root package.json file
npm i @escook/request-miniprogram -S Download network request package
2. open main.js
Entrance file
import { $http } from '@escook/request-miniprogram'
// Introduce... From the network request packet $http Request object
uni.$http = $http
// Because it is also used in other pages or components , So will $http The object is attached to the global object , stay uni-app in ,uni Global object
$http.baseUrl = 'https://www.baidu.com'
// Configure network request base address , because uni.$http by $http References to , So you can modify it directly $http Properties under the object
$http.beforeRequest = function() {
// Configure the interception function before initiating the network request
uni.showLoading({
title: ' Loading ...'
})
}
$http.afterRequest = function() {
// Configure the interception function after the network request
uni.hideLoading()
}
// Encapsulation request failure prompt
uni.$showMsg = function(title=' Data load failed ',duration=1500){
uni.showToast({
title,
duration,
icon:'none'
})
}
3. Initiate network request
async getSwiperList() {
const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
if (res.meta.status !== 200) return uni.$showMsg()
this.swiperList = res.message
}
边栏推荐
- AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
- leetcode704. 二分查找(查找某个元素,简单,不同写法)
- Internal and external troubles of "boring ape" bayc
- The difference between get and post request types
- Database basics exercise part 2
- UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
- Proteus -- Serial Communication parity flag mode
- Introduction to ros2 installation and basic knowledge
- NFT on fingertips | evaluate ambire on G2, and have the opportunity to obtain limited edition collections
- 从autojs到冰狐智能辅助的心里历程
猜你喜欢
Kubernetes cluster builds ZABBIX monitoring platform
19. Actual memory management of segment page combination
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
Leetcode 78: subset
Cif10 actual combat (resnet18)
The author is dead? AI is conquering mankind with art
Internal and external troubles of "boring ape" bayc
因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
RichView TRVStyle 模板样式的设置与使用
开源的网易云音乐API项目都是怎么实现的?
随机推荐
GET 和 POST 请求类型的区别
At the age of 26, I changed my career from finance to software testing. After four years of precipitation, I have been a 25K Test Development Engineer
【服务器数据恢复】IBM服务器raid5两块硬盘离线数据恢复案例
Misc of BUU (update from time to time)
leetcode59. 螺旋矩阵 II(中等)
1189. Maximum number of "balloons"
Pymongo gets a list of data
Windows Server 2016 standard installing Oracle
Cookie技术&Session技术&ServletContext对象
【每日一题】729. 我的日程安排表 I
supervisor 使用文档
WPF之MVVM
19.段页结合的实际内存管理
【Hot100】739. 每日溫度
leetcode1020. Number of enclaves (medium)
librosa音频处理教程
Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
Simple use of JWT
简单描述 MySQL 中,索引,主键,唯一索引,联合索引 的区别,对数据库的性能有什么影响(从读写两方面)
Raspberry pie 3B update VIM