1. naviagtor
open-type:
- navigate 有返回
- redirect 无返回
- switchTab 跳转有 tabBar的页面
2. tabBar
在 app.json中设置,
- pagePath 必须在pages中设置/pages/...
- iconPath 不支持 网络图片
- selectedIconPath 不支持网络图片
- text 文字
3. background-image
小程序background-image不支持本地资源,要base64格式/网上链接
4. text
text 中引用空格:
- 首先需要设置
<text>
控件的decode值 - decode可以解析的有
< > & '    
eg:
<text decode="emsp" style="color:#fff;">相爱一生   陪伴到老</text>
- ensp 中文字符空格一半大小
- emsp 中文字符大小
- nbsp 根据字体设置的空格大小
5.箭头函数
箭头函数 不能使用this
6. 获取屏幕宽度、高度
this.setData({
imageWidth: wx.getSystemInfoSync().windowWidth
})
7. 设置全局变量
app.js
globalData:{
userInfo:null,
imgUrl:'http://xu.jeft-hai.top/images/'
}
使用
*.js
var app = getApp();
var imgUrl= app.globalData.imgUrl;
data({
imgUrl:imgUrl
})
8. 背景音乐
// play
const backgroundAudioManager = wx.getBackgroundAudioManager();
backgroundAudioManager.src = this.data.musicList[idx];
backgroundAudioManager.title = ' ';
backgroundAudioManager.startTime = 8;
BackgroundAudioManager.play();
ios下必须有title才可以播放
// pause
const backgroundAudioManager = wx.getBackgroundAudioManager();
backgroundAudioManager.pause();
9.数据渲染
wx:for="{{}}" wx:for-item='"item" wx:key='key' wx:for-index="index"
10. 预览图片
previewImage(e){
var dataset = e.target.dataset;
var path = dataset.path;
var target = dataset.target;
var src = this.data.imgUrl + this.data.person +'/' + path + '/' + target;
var list = dataset.list;
var urls = [];
list.forEach((item,index)=>{
item = this.data.imgUrl + this.data.person + '/' + path + '/'+item;
urls.push(item);
})
wx.previewImage({
urls: urls, // arr
current:src // 当前
})
}
11. 分享
onShareAppMessage: function () {
return {
title: '', // 默认小程序的名字 必须有
desc: '', // 默认小程序的名字 不必有
imageUrl: '', // 有:img, 没有: 页面截屏
path: '/template/temp/temp?id='+this.data.idx
}
}