이 글은 주로 WeChat 애플릿의 post 메소드와 get 메소드 패키징에 대한 관련 정보를 소개합니다. 이 글이 모든 사람에게 캡슐화 방법을 알리고 도움이 되길 바랍니다.
WeChat 애플릿 개발 포스팅을 참조하세요. 메소드 캡슐화 및 메소드 가져오기
1단계: utils 폴더에 httpUtil.js 파일 생성
2단계: 다음과 같이 httpPost 메소드 코드 함수 생성:
function Post(url, data, cb, isShow, showNetError, that, showLoading) { if (showLoading == true || showLoading == undefined){ wx.showNavigationBarLoading(); wx.showLoading({ title: '加载中...', }) } var basicData = { vloginPwd: api.vloginPwd, vtoken: api.vtoken } if (!isEmpty(data)) { for (var key in data) { try { basicData[key] = data[key]; } catch (e) { } } } wx.request({ url: url, header: { 'content-type': 'application/x-www-form-urlencoded' }, method: 'POST', data: basicData, success: (res) => { if (res.data.state == 200) { typeof cb == "function" && cb(res.data, ""); } else { if (isShow == true) { wx.showModal({ title: '提示', content: res.data.msg, showCancel: false }) } } }, fail: (err) => { if (showNetError) { that.setData({ errorDisplay:'', containHidden:true }) } }, complete: (res) => { setTimeout(function () { wx.hideNavigationBarLoading(); wx.hideLoading(); }, 100) } }); };
3단계, 모듈에 추가됨 :
module.exports = { httpGet: Get, httpPost: Post };
4단계 소개
var httpUtil = require('../../utils/HttpHelper.js')
5단계 사용법
onload:function(option){ var that = this; httpUtil.httpPost(api.getListUrl, jsonData, function (res) { wx.showModal({ title: '提示', content: res.msg, showCancel: false, confirmText:"查看", success: function (res) { console.log("res.data===", res.data); if (res.confirm) { that.toDetail(res.data); } } }) }, true, true, this); }
이상이 이 글의 전체 내용입니다. 도움이 되셨으면 좋겠습니다 모두의 학습을 위해, 더 많은 관련 콘텐츠를 보려면 PHP 중국어 웹사이트에 주목하세요!
관련 권장사항:
WeChat 애플릿의 네트워크 요청(요청 게시 및 요청 받기)
WeChat 애플릿의 promsie.all 및 promise의 순차적 실행
위 내용은 WeChat 애플릿에서 post 메소드와 get 메소드 캡슐화의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

Eclipse용 SAP NetWeaver 서버 어댑터
Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구
