The ideas of WeChat applet and Vue are very similar and can be compared and learned from each other
Store data locally:
var
userName = wx.setStorageSync( 'username' , 'root' ) ;//Store the value of username root locally
var
userName = wx.getStorageSync(
'userName'
);//Get the value of local username
wx.removeStorageSync(
'username'
);//Clear the locally stored username
page jump to pass two values:
page jump to pass two values:
wx.navigateTo({//Page jump to return
url:
'../Collectordemo/Collectordemo?datas='
+ str + '&id=' + openid
})
})
wx.switchTab({// The page jumps to the tab page
url:
'../order/order'
})
wx.redirectTo({// Close the current page and jump to another page
url:
'../order/order'
})
wx.relaunch({// Close all pages and jump to another page
url:
'../order/order'
})
Get the value passed on the previous page:
var
dingdan = options.datas;
图片上传多个时可以在
wx.chooseImage时将
图片上传到服务器,后台接收每一张图片,
将图片的服务器地址返回,存储该地址和其他数据一起在data中返回给服务器。
var
id= options.id;
获取后台数据:
图片上传:
获取后台数据:
wx.request({
url: urls +
'/order/orders/'
+ dingdan,
header: {
'Content-Type'
:
'application/json;charset=UTF-8'
},
data: {
id: dingdan
},
success:
function
(res) {
if
(res.data.code ==
200
) {
that.setData({
listdata: res.data.data,
arraylist: res.data.data.orderDetailVOS
})
}
else
{
console.log(res.data.msg);
}
}
})
wx.request({//上传数据
wx.request({//上传数据
url: urls +
'/order/orders/'
+ that.data.dingdanId +
'/ok'
,
header: {
'Content-Type'
:
'application/json;charset=UTF-8'
},
data: {
id: that.data.dingdanId,
items: JSON.stringify(that.data.arraylist)
},
method:
"POST"
,
success:
function
(data) {
if
(data.data.code ==
200
) {
wx.showToast({
title:
'提交成功!'
,
icon:
'success'
,
duration:
2000
})
}
else
{
console.log(data)
}
}
})
图片上传:
将图片的服务器地址返回,存储该地址和其他数据一起在data中返回给服务器。