原因:
因为 iOS 下加了 -webkit-overflow-scrolling: touch,这个会产生滚动惯性,体验更好,但会改变 fixed 的行为,建议不在 scroll-view 里有 fixed 元素
方案:在APP.vue下添加如下样式
1 2 3
| .wx-scroll-view { -webkit-overflow-scrolling: auto; }
|
uniapp中同步获取及设置 storage
1 2
| uni.getStorageSync('key') uni.setStorage({key: 'merchantInfo',data: value})
|
Promise异步请求,设置最大并发数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| requestByMax(urls,max){ return new Promise((resolve)=>{ if(urls.length===0){resolve([])return ; } const results=[] let index=0 let count=0 let that=this async function request(){ if(index==urls.length) return; let i=index let url=urls[index] index++ try{ let res= await that.$http.get(url) results[i]=res }catch(err){ results[i]=err }finally{ count++ if(count===urls.length){ console.log('over') resolve(results) } request() } } for(let j=0;j<max;j++){ request() } }) }
|
nodeJs连接数据库长时间未访问数据库断开连接(the server close the connection)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| var mysql = require('mysql');
const mysqlConf = { host: '127.0.0.1', user: 'root', password: '123456', database: '数据库名', multipleStatements: true };
var c = null; var pingInterval;
function handleError(err) { logger.info(err.stack || err); connect(); }
function connect() { if (c !== null) { c.destroy(); c = null; } c = mysql.createConnection(mysqlConf); c.connect(function (err) { if (err) { logger.info("error when connecting to c,reConnecting after 2 seconds:", err); setTimeout(connect, 2000); } }); c.on("error", handleError);
clearInterval(pingInterval); pingInterval = setInterval(() => { console.log('ping...'); c.ping((err) => { if (err) { console.log('ping error: ' + JSON.stringify(err)); } }); }, 3600000); } connect(); module.exports=c;
|
express快速创建服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| const express=require('express') const cors=require('cors') const myRouter=require('./routes/index') const app=express() const createError = require('http-errors'); app.listen(3000,()=>{ console.log('start') }) app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.use(express.static('public')) app.use(cors()) app.use('/api', myRouter) app.use(function (req, res, next) { res.send({ code: 404, msg: '资源不存在' }) }); app.use(function (err, req, res, next) { console.log(err) res.send({ code: 500, msg: '服务器端错误' }) }); module.exports = app;
|
jsonwebtoken接口权限验证
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| const jwt = require("jsonwebtoken") const tokenSecret = "你的秘钥" module.exports = (req, res, next) => { let token =req.headers.authorization if (!token) { res.send({ code: 4100, msg: "token required" }) return } try { let payload = jwt.verify(token, tokenSecret) if (Date.now() > payload.expires) { res.send({ code: 4102, msg: "token expires" }) } else { req.token = payload next() } } catch (err) { res.send({ code: 4101, msg: "token invalid" }) } }
|
文件上传接口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| let upload=multer({ storage: multer.diskStorage({ destination: 'public/img', filename(req, file, cb) { const { originalname } = file const i =originalname.lastIndexOf('.') const ext =originalname.slice(i) const name = uuid.v4() + ext cb(null, name) } }) }) router.post('/upload',upload.single('file'),(req,res,next)=>{ let {originalname} =req.file if (!req.file) { res.send({ code: 4000, msg: "upload error" }) return } if(true){ res.send({code:200,url:'静态资源地址/'+req.file.filename}) } })
|
AJAX请求步骤
1.创建HTTP请求对象
1
| var xhr = new XMLHttpRequest()
|
2.打开服务器的连接,设置要请求的接口
1
| xhr.open(请求方式, 接口地址, 是否为异步)
|
请求方式标准写法为大写,是否为异步默认为true,异步
3.发送请求
4.绑定事件,监听服务器端响应
1 2 3
| xhr.onload = function(){ xhr.responseText }
|
SQL列自增排序
1 2 3
| SET @auto_id = 0; UPDATE hotel SET h_id =(@auto_id :=@auto_id +1); ALTER TABLE hotel AUTO_INCREMENT = 1;
|
Vite创建vue项目
创建命令 npm create vue@latest // npm init vue@latest