wepy封装post get请求!!

1): 在src目录下新建baseAPI.js文件;
wepy封装post get请求!!_第1张图片
2):在文件头部引入wepy;
import wepy from ‘wepy’;
3): 拼接网址

const baseURL = 'https://www.zhuzhu.com/nasp.php';

3):封装提示框;

wepy.baseToast = function (str = '') {
	wepy.showToast({
		title: str,
		icon: 'none',
		duration: 1000
	})
}

封装get请求;

wepy.get = function (url, data = {}) {
	return wepy.request({
		url: baseURL + url,
		method : 'GET',
		data
	})
}

封装post请求;

wepy.post  = function (url, data = {}) {
	return wepy.post({
		url: baseUrl + url,
		method: 'POST',
		data
	})
}

然后在全局app.wpy中引用;
import ‘@/baseAPI.js’

你可能感兴趣的:(个人)