sublimetext小程序代码编辑的一个插件
发布于 6 年前 作者 tao47 13169 次浏览 来自 问答

sublimetext小程序代码编辑的一个插件

https://gitee.com/abis/WxappPlugin4SublimeText

比如数据请求,键入:wxrequest(或前几个字母,忽略大小写)回车后会自动出来:

// 请求服务器
wx.showLoading({
    title: '加载中...',
    mask: true
});
 
wx.request({
    url: configGlobal.server.request_url + '/_WxaappApiServer/',
    data: {
        openId: app.globalData.openId,
         
    },
    method: 'POST', // GET, POST, OPTIONS, HEAD, PUT, DELETE, TRACE, CONNECT
    dataType: 'json',
    header: {
        // 'Content-Type': 'application/json; charset=utf-8' // 如果请求用GET
        'content-type': 'application/x-www-form-urlencoded'
    },
    success: function(res) {
        wx.hideLoading();
        console.log('request成功,服务端返回res:', res);
 
        if (res.data.result == true) {
            var obj = res.data.data;
            console.log("返回数据 obj:", obj);
             
            that.setData({
            });
        }else{
            console.log('获取失败: ', res.data.message);
            wx.showToast({
                title: '获取失败!',
                mask: true,
                duration: 2000
            });
        }
    },
    fail: function(res) { console.log('request fail res:', res); },
    complete: function(res) { wx.hideLoading(); }
});

推荐给大家!

1 回复

感谢推荐

回到顶部