java恶作剧小程序_[Java教程]超好用超短的小程序请求封装

[Java教程]超好用超短的小程序请求封装

0 2018-07-22 20:00:56

超好用超短的小程序请求封装,也不算特别特别短吧哈哈哈。但真的很好用的一个小程序请求封装,在请求的时候简短提高效率不需要将一样的东西重复写。下面就让大家看看这个封装是有多短,不够短的话也请别打我

网上多数使用的小程序封装是在单独的一个js文件,再使用module.exports进行输出方法。我所介绍的封装方法有异曲同工之妙,只不过是写在app.js里边,省去了使用时必须引用文件的麻烦。

app.jsxcxPost(options = {}) { wx.showLoading({ mask: true, title: '', }) wx.request({ url: this.globalData.postUrl + options._url, data: options._data || {}, method: "POST", dataType: "json", header: this.globalData.header, success: (res) => { if (res.data.errcode > 0) { if (typeof options._success == "function") { options._success(res.data); } } else { this.xcxErrorToast({ title: res.data.errmsg || '服务器返回错误!' }); return; } }, fail: (res) => { if (typeof options._fail == "function") { options._fail(res); } if (typeof options._fail == "string") { //请求失败的弹框提示 wx.showToast({ title: options._fail, icon: 'loading', duration: 2000 }); } }, complete: (res) => { if (typeof options._complete == "function") { options._complete(res); } wx.hideLoading() } }); },

此处的this.globalData,是在app.js设置的,也就是小程序的全局属性,不了解的朋友请查阅小程序官方文档

而以上封装具体的返回参数说明,请移步官方文档   https://developers.weixin.qq.com/miniprogram/dev/api/network-request.html#wxrequestobjectApp({ globalData:{ userInfo:{}, postUrl: (wx.getExtConfigSync().request_url || '(后台接口地址)'), header: { 'content-type': 'application/x-www-form-urlencoded', 'Cookie': '' }, },

其他页面引用封装请求,比如 index.js/** * http请求 * 获得banner图 */ getShopId(callBack) { app.xcxPost({ _url:'pc_home_page/banner',// 你需要发起的请求; _data: { type: '1' },// 你需要传的请求参数; _success: (resp) => {//请求成功后的操作;if (resp.errcode > -1) { // this.globalData.shopId = resp.list.shopId; // this.globalData.domainUrl = resp.list.domain; if (callBack) { callBack() } } }

}) },

本文网址:http://www.shaoqun.com/a/363375.html

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:admin@shaoqun.com。

小程序

0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以计算加减乘除的计算器小程序package zj lec1; import java awt BorderLayout; import java awt FlowLayout; import java awt GridLayout; import java awt event ActionEvent; import java awt event ActionListener; import java math BigInteger; import javax swing JButton; import javax swing JFrame; import javax swing JLabel; import javax swing JPanel; import javax swing JTextField; public class 简易计算机 extends JFrame implements ActionListener { JTextField a b c d; JButton ok exit; public 简易计算机 { this setLayout new FlowLayout ; this add a new JTextField 10 ; a setText "0" ; a setHorizontalAlignment JTextField RIGHT ; this add b new JTextField 1 ; this add c new JTextField 10 ; c setText "0" ; c setHorizontalAlignment JTextField RIGHT ; this add ok new JButton " " ; this add d new JTextField 10 ; this add exit new JButton "Exit" ; a addActionListener this ; b addActionListener this ; c addActionListener this ; exit addActionListener this ; ok addActionListener this ; this setSize 540 70 ; this setTitle "简易计算机" ; this setVisible true ; this setResizable false ; } public static void main String[] args { new 简易计算机 ; } @Override public void actionPerformed ActionEvent e { if e getSource ok || e getSource c || e getSource a { BigInteger ia new BigInteger a getText ; BigInteger ic new BigInteger c getText ; String ib b getText ; 判断是用加法 还是减法 还是乘法 除法 if ib contains "+" { BigInteger id ia add ic ; d setText id toString ; } else if ib contains " " { BigInteger id ia subtract ic ; d setText id toString ; } else if ib contains " " { BigInteger id ia multiply ic ; d setText id toString ; } else if ib contains " " { BigInteger id ia divide ic ; d setText id toString ; } } else if e getSource exit { System exit 0 ; } } }">可以计算加减乘除的计算器小程序package zj lec1; import java awt BorderLayout; import java awt FlowLayout; import java awt GridLayout; import java awt event ActionEvent; import java awt event ActionListener; import java math BigInteger; import javax swing JButton; import javax swing J [更多]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值