微信小程式開發 筆記
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
})