原創聲明:本文為作者原創,未經允許不得轉載,經授權轉載需注明作者和出處
wxml主要代碼
<view wx:for="{{array}}" >
{{item.value}}
</view>
<input bindinput="confirm" placeholder="留言內容" />
<button bindtap="click" >發送</button>
js主要代碼
// 輸入完成
confirm: function (e) {
newnote = e.detail.value
},
//留言
click: function (e) {
var that = this
wx.request({
url: ‘https://api.wxappclub.com/put‘,
data: {
appkey: ‘XX’,
key: “key_@”,
type:”message”,
value:newnote
},
header: {
‘content-type’: ‘application/json’
},
success: function (res) {
wx.request({
url: ‘https://api.wxappclub.com/list‘,
data: {
appkey: ‘xx’,
type:”message”
},
header: {
‘Content-Type’: ‘application/json’
},
success: function (res) {
that.setData({
array: res.data.result
})
}
})
}
})
}
算是模擬數據庫的用法把,put API用—@隨機key,加type類似字段名,實現插入數據。讀取數據用list API,獲取數組后wx-for輸出。