setData
- Modify the
data
Property value of the neutron object, used[key]
data:{
user_info:{
name: 'Rainy', age: 19}} // change name to Mis_chensetThe Data again! , the following methodslet key = "user_info.name" ;
this.setData({
[key]: "Mis_chen"
})
Copy the code
- Modify the array
array
A child property of a subscript. On top of that,variable
useString splicing
Can be
data:{
arr:[{ name: 'aa' }, { name: 'bb'}]} // Change the subscript to 1, name to ddletindex = 1; // Used for testing, usually as a parameter passed inlet key = 'array' + '[' + index + '].name' ;
this.setData({
[key]: "dd"
})
Copy the code
Forced to upgrade
App.js /** * Force update */ const updateManager = wx.getupDatemanager (); updateManager.onCheckForUpdate(function(res) {// Request a callback for the new version informationif (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: 'Update Prompt',
content: 'The new version is ready. Do you want to restart the application? ',
success: function (res) {
if(res. Confirm) {/ / download the new version of good, call applyUpdate application. The new version and restart updateManager applyUpdate ()}}})}) updateManager. OnUpdateFailed (function() {// New version download failed wx.showmodal ({title:'There is a new version.',
content: 'New version has been online ~, please delete the current small program, search again open yo ~'})})}})Copy the code
Network monitoring
Wx.getnetworktype ({success:function(res) {
let networkType = res.networkType ;
if(networkType == "none"){
that.globalData.isConnected = false ;
wx.showToast({
title: 'No network at present',
icon: 'loading', duration:2000})}},}) /** * Monitor network status, adjust according to service */ wx.onNetworkStatuschange (function(res){
if(! res.isConnected){ that.globalData.isConnected =false ;
wx.showToast({
title: 'Network disconnected',
icon: 'loading',
duration: 2000,
complete:function(){// Business logic after disconnect}})}else {
that.globalData.isConnected = true; wx.hideToast() ; }})Copy the code