1.[wxss]设置带透明度的rgb颜色:rgb(0,0,0,0.5);
2.小程序使用类似于iOS的NSNotification:(第三方:https://github.com/icindy/WxNotificationCenter)
(1)在需要收发通知的页面引入WxNotificationCenter:
var WxNotificationCenter = require("../../../component/WxNotificationCenter/WxNotificationCenter.js");
(2)onLoad时注册监听,onUnload时移除监听
WxNotificationCenter.addNotification("didSelectOrderClient", this.didSelect, this)
WxNotificationCenter.removeNotification("didSelectOrderClient", this)
(3)发送通知
WxNotificationCenter.postNotificationName("didSelectOrderClient");
3.[wxss]文字不换行,超出部分显示省略号:
white-space: nowrap;
overflow: hidden;
text-overflow:ellipsis;
4.[js]导航返回多页
wx.navigateBack({
delta:2
})
5.延时操作
setTimeout(function () {
//要延时执行的代码
}, 1000) //延迟时间 这里是1秒
6.创建对象时,若属性名为变量,需要加[],如:
params: {
[key]:value,
},
7.获取对象属性值时,若属性名为变量,用“.”无法获取,则可以用[],如:
permission[mykey]
8.json字符串->对象(如:从服务器接口获取到字符串转数组对象):
var jsonObj = JSON.parse(jsonStr);
9.对象->json字符串(如:页面传值时的对象类型,可以先转字符串,到新页面后再转回对象):
var jsonStr = JSON.stringify(jsonObj)
10.js获取控件的高度
首先给你的xml对象一个id:
<view class="usermotto" style="height:213px;" id='mjltest'/>
然后在js里,用一个SelectorQuery来选择对应id的节点(注意id前面要加一个#号),就可以获取对应节点的属性,包括高度:
//创建节点选择器
var query = wx.createSelectorQuery();
//选择id
query.select('#mjltest').boundingClientRect()
query.exec(function (res) {
//res就是 所有标签为mjltest的元素的信息 的数组
console.log(res);
//取高度
console.log(res[0].height);
})
11.数据回传上一页
let pages = getCurrentPages()
let prePgae = pages[pages.length - 2]
prePgae.setData({
needUpdate: true
})
12.深入理解css中position属性及z-index属性:https://www.cnblogs.com/zhuzhenwei918/p/6112034.html
13.js中获取view宽度、高度
//创建节点选择器
var query = wx.createSelectorQuery();
//选择id
query.select('.card_top_content').boundingClientRect(function (rect) {
console.log(rect.height)
console.log(rect.width)
}).exec();
14.【wxss】button 设置为透明:
.a_button{
background-color: rgba(255, 255, 255, 0);
}
.a_button::after {
border: 0;
}
15.showModal不显示取消按钮:
wx.showModal({
title: '提示',
content: res.data.message,
showCancel: false
})