js如何实现深拷贝:
简单易用的深拷贝(不能拷贝对象中的方法):
let obj = {name:'tom',age:18};
let newObj = JSON.parse(JSON.stringify(obj) );
https://www.jb51.net/article/162551.htm
js 删除字典(对象)的键值对:
let d = {name:'tom',age:18}; delete(d['name']); console.log(d);
微信小程序使用vant:
百度一下,
微信小程序 调起手机端 导航进行导航:
beginNav(){ wx.chooseLocation({ success(res) { wx.openLocation({ latitude:res.latitude, longitude:res.longitude, name:`${res.address} | ${res.name}` }) } }) }
注:用户需要先授权,
微信小程序获取地理位置授权,首先需要在app.json中添加配置:
"permission": { "scope.userLocation": { "desc": "请确认授权以获取您的地理位置" } }
如果手机未开启位置信息,那么授权成功后在wx.getLocation()方法中也会一直失败,所以需要在fail方法中提示用户开启手机位置信息
错误和异常:
https://www.cnblogs.com/zhangboyu/p/7911190.html
错误是error 异常时 exception
错误是可能出现问题的地方出现了问题,例如打开文件失败。 业务的一部分。
异常是不应该不应该出现问题的地方出现了问题,例如引用了空指针,除数为0。不应是业务的一部分。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
func test() { defer func() { err := recover() //recover内置函数可以捕获到异常 if err != nil { //nil是err的零值 fmt.Println("err=", err) fmt.Println("发送信息给管理员admin@steven.com") } }() a := 10 b := 0 res := a / b fmt.Println(res) } func main() { test() // test 函数中可能 会有异常 退出 的情况,故 test()中要用 defer recover() fmt.Println("hello world") }
微信小程序form 表单 模板 mpvue 中:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<div class="test"> <form @submit="submitEvt"> <div class="item"> <span>用户名</span> <input placeholder-class="ph_cls" type="text" name="userName" placeholder="请输入用户名"> </div> <div class="item"> <span>密码</span> <input placeholder-class="ph_cls" password name="pwd" placeholder="请输入密码" > </div> <button style="margin: 30rpx 0" type="primary" formType="submit">提交</button> <button style="margin: 30rpx 0" formType="reset">Reset</button> </form> </div>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
.test{ padding: 10rpx 10rpx; } .test .item{ display: flex; align-items: center; border-bottom: 1px solid #F5F5F5; } .test .item span{ width: 20%; font: normal 30rpx '微软雅黑'; } .test .item input{ padding: 10rpx 10rpx; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
.ph_cls{ font: normal 24rpx '微软雅黑'; color: #646566; }
使用ajax 发送 json 数据 :
注意事项:
微信小程序 下载文件:
预览pdf:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<template> <div>我的界面 <div @tap="previewDoc">查看pdf</div> </div> </template> <script> export default { methods:{ previewDoc:function () { wx.downloadFile({ url:"https://6an.com/static/C_Make_License.pdf", success(res) { // console.log(res); if(res.statusCode === 200){ // console.log( res.tempFilePath); let filePath = res.tempFilePath; // 预览该文件 wx.openDocument({ filePath:filePath, success(res) { // console.log("打开文件成功"); // console.log(res); }, fail(res) { // console.log("打开文件失败"); // console.log(res); } }) } } }) } } } </script> <style scoped> </style>
微信小程序 上传文件:
小程序端:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<template> <div>我的界面 <div @tap="uploadDoc">上传文件</div> </div> </template> <script> export default { methods:{ uploadDoc:function () { wx.chooseMessageFile({ count:1, type:"file", success (res) { console.log(res); let tempFiles = res.tempFiles[0]; wx.uploadFile({ url: 'https://oyan.com/upload/', filePath: tempFiles.path, name: 'file', formData: { 'file_name': tempFiles.name }, success (res){ const data = res.data; //do something }, fail(res) { console.log(res); } }) } }) } } } </script> <style scoped> </style>
服务端 flask :
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
@app.route("/upload/",methods=["post"]) def upload(): my_file = request.files.get('file') file_name = request.form.get("file_name") my_file.save(file_name) return "ok"
常用css 样式:
清除浮动:
.clearfix:after { content: ""; display: block; clear: both; }
横线绘制:
.my_line { width: 90%; height: 1rpx; border-bottom: 1rpx solid #ccc; position: absolute; left: 5%; } .my_last_line { width: 100%; height: 1rpx; border-bottom: 1rpx solid #ccc; position: absolute; left: 0; }
超出文本显示 三个点:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;