当前位置:网站首页>Summary of common errors in wechat applet cloud development
Summary of common errors in wechat applet cloud development
2022-07-24 04:44:00 【. sigh】
Catalog
One Use API When accessing cloud database where Conditions
Two Use API The operation of cloud database is asynchronous
3、 ... and Code package size exceeded .
One Use API When accessing cloud database where Conditions
1. Use API When accessing cloud database where Conditions must not be underfind, Otherwise it will get stuck .
db.collection('user').where({
_openid: openId
})So when openId It must not be underfind.
Two Use API The operation of cloud database is asynchronous
2. Use API The operation of cloud database is asynchronous , At this time, the access task will be added to the opposite column , Wait for other statements below to execute first, and then operate the database . Therefore, if in the callback when operating cloud database setdata The new data , Then call in parallel under the operation database function API Operating the database , here where It can't be the new one above setdata The data of . Because the callback function has not been executed at this time .
Write it correctly : The second operation database should be encapsulated into a function , Call in the callback function for the first time , Or write the code directly into the first callback to execute .
success(res) {
if (res.confirm) {
wx.showLoading({
title: ' Data loading ...',
});
const db = wx.cloud.database({ // Link data table
env: ""
});
// Favorite list string processing
var delete_id = that.data.list[e.currentTarget.dataset.index]._id
var arrCollectionstr = that.options.collectionstr.split(',')
var new_collectionstr = ''
for (let index = 0; index < arrCollectionstr.length; index++) {
if (arrCollectionstr[index] != delete_id) {
new_collectionstr += arrCollectionstr[index]
if (index != arrCollectionstr.length - 1) {
new_collectionstr += ','
}
}
}
// modify user database
db.collection('user').where({
_openid: that.data.openid
}).update({
data: {
Collection: new_collectionstr
},
success: function (res) {
wx.showToast({
title: " Triple curtain : Modification successful , Please reload after returning ", // Content of tips
icon: "none", // Icon , Default success
image: "", // The local path of the custom icon ,image Has a higher priority than icon
duration: 3000, // Delay time of prompt , Default 1500
mask: false, // Whether the transparent mask is displayed , Prevent touch penetration
})
wx.hideLoading();
}
})
}
}notes : If the operation is repeatable, it is recommended to package it as a function , This is convenient for later maintenance . And prevent the situation of writing continuous multi-layer dolls by operating the database .
3、 ... and Code package size exceeded .
It is recommended to put the icons with small volume directly outside the code package , All other pictures are suggested to be stored directly in the cloud , Invocation time src Directly fill in and generate as http Address , This can effectively reduce the size of the code package , Another thing to note is that images are generated when they are stored in the cloud http Address validity is related to permissions , If only the creator can read , Then the validity period is one month , If everyone can read , The term of validity is permanent .
边栏推荐
- In the business interaction and foreign service of.Gz, we integrate multiple models
- [2023 core technology approval test questions in advance] ~ questions and reference answers
- How long has it been since you changed your cell phone?
- 数组力扣(持续更新)
- Print leap years between 1000 and 2000
- What is the general family of programmers working in first tier cities?
- MySQL constraint_ Foreign key constraint
- Determined by hardware (see official 2 and
- 可以脱离设据生效这些都是控化部署能力,而后引如
- How is it that desktop icons can't be dragged? Introduction to the solution to the phenomenon that desktop file icons can't be dragged
猜你喜欢

《论文复现》BiDAF代码实现过程(3)模型建立

激活函数和最常用的10个激活函数
![[essay] goodbye to Internet Explorer, and the mark of an era will disappear](/img/1f/1fa596cf89bbade3079271dc1c324f.png)
[essay] goodbye to Internet Explorer, and the mark of an era will disappear

Gau and ppm for image semantic segmentation

pycharm 调试功能介绍与使用

Forward proxy, reverse proxy and XFF

归并排序(Merge sort)

LabVIEW master VI freeze pending

How can e-commerce projects solve the over issuance of online coupons (troubleshooting + Solutions) (glory Collection)

Can NFT pledge in addition to trading?
随机推荐
LabVIEW master VI freeze pending
C language: selective sorting method
What if the computer desktop gets stuck? Introduction of solutions to computer crash and desktop jamming
Several common sorts
Merge sort
J9 number theory: what is Web3.0? What are the characteristics of Web3.0?
Question 146: LRU cache
力扣146题:LRU缓存
口叫SC 或者 pb 文件为读写控制ensor为
LabVIEW主VI冻结挂起
数组力扣(持续更新)
In the business interaction and foreign service of.Gz, we integrate multiple models
Add.Eslinctrc.js under SRC for the general format of the project
A hospital call system based on C language
The problem of monkeys eating peaches in classic exercises of C language
PHP修改配置文件的两种方法
Why can't I hide folders? Solutions to the hidden folders on the computer that can still be seen
Teacher qiniu said is the VIP account opened for you safe?
These are controlled deployment capabilities, and then cited as
Middle aged crisis, workplace dad who dare not leave, how to face life's hesitation