习惯了微信小程序的,最初不习惯的很,总结了以下几个支付宝小程序开发遇到的问题:
获取input 的value值
<input class="input" type="number" value="{{inputValue}}"onInput="bindKeyInput" placeholder="请输入激活码" />
<button type="ghost" onTap="submitClick">提交</button>
此时我想获取input的value值,并使用它
Page({
data: {
inputValue: ''
},
onLoad() {},
bindKeyInput(e) {
this.setData({
inputValue: e.detail.value,
});
},
});
最初尝试:
this.inputValue 获取失败
最后:
this.data.inputValue 终于获取成功了
缓存
my.setStorage({ key: 'key', data: { key: res.data.key } });
获取缓存
let res1 = my.getStorageSync({ key: 'key' }).data;
console.log(res1.key) //这个才是我要获取的key值
网络请求 my.request
my.request 目前支持 GET/POST/PUT/DELETE(其中 PUT、DELETE 请求在支付宝客户端 10.1.82 或更高版本支持)。
my.request 目前只支持 https 协议的请求。
submitClick() {
my.request({
url: 'https://xxx.com/web/?code=' + this.data.inputValue, // 目标服务器url
method: 'get',
data: {},
headers: {
'content-type': 'application/json' //默认值
},
dataType: 'json',
success: function(res) {
console.log(res)
/* 缓存数据
my.setStorage({
key: 'key',
data: {
key: res.data.key
}
}); */
},
fail: function(res) {
my.alert({
content:res.data.errMsg
});
},
//调用结束的回调函数(调用成功、失败都会执行)
complete: function(res) {
my.hideLoading();
my.alert({
content: 'complete'
});
}
});
}