当前位置:网站首页>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
}
边栏推荐
- Leetcode59. spiral matrix II (medium)
- Entity Developer数据库应用程序的开发
- Cookie Technology & session Technology & ServletContext object
- The author is dead? AI is conquering mankind with art
- Configure raspberry pie access network
- Refer to how customer push e-commerce does content operation
- leetcode1020. Number of enclaves (medium)
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Brief introduction to the curriculum differences of colleges and universities at different levels of machine human major -ros1/ros2-
- 首发织梦百度推送插件全自动收录优化seo收录模块
猜你喜欢
Configure raspberry pie access network
RichView TRVStyle 模板样式的设置与使用
The best way to learn SEO: search engine
Thought map of data warehouse construction
Oracle数据库11gr2使用tde透明数据加密报错ora28353,如果运行关闭wallet会报错ora28365,运行打开wallet就报错ora28353无法打开wallet
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
顶测分享:想转行,这些问题一定要考虑清楚!
医疗软件检测机构怎么找,一航软件测评是专家
变量的命名规则十二条
微信公众号无限回调授权系统源码 全网首发
随机推荐
kubernetes集群搭建Zabbix监控平台
变量的命名规则十二条
Due to high network costs, arbitrum Odyssey activities are suspended, and nitro release is imminent
Apache dolphin scheduler source code analysis (super detailed)
leetcode6109. 知道秘密的人数(中等,周赛)
BUU的MISC(不定时更新)
How to find a medical software testing institution? First flight software evaluation is an expert
19.段页结合的实际内存管理
Bitcoinwin (BCW): the lending platform Celsius conceals losses of 35000 eth or insolvency
NFT on fingertips | evaluate ambire on G2, and have the opportunity to obtain limited edition collections
[hot100] 739. Température quotidienne
Do you really know the use of idea?
Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
【Hot100】739. 每日溫度
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
Simple use of JWT
Proteus -- Serial Communication parity flag mode
“无聊猿” BAYC 的内忧与外患
Pymongo gets a list of data
首发织梦百度推送插件全自动收录优化seo收录模块