1. created 生命周期回调—监听页面加载
2. attached 生命周期回调—监听页面显示
3. ready 生命周期回调—监听页面初次渲染完成
4. moved 生命周期回调—监听页面隐藏
5. detached 生命周期回调—监听页面卸载
6. error 每当组件方法抛出错误时执行
<view wx:for="{{array}}" wx:for-index="myIndex" wx:key="myIndex" wx:for-item="myItem" >
{{myIndex}}: {{myItem}}
</view>
<view bindtap="goNextPage" data-id="{{1}}" data-name="{{'默认收藏'}}">默认收藏</view>
goNextPage(e) {
const { id = null, name = ''} = e.currentTarget.dataset
console.log('id:',id)
wx.navigateTo({
url: '/pages/collect/details/index',
})
}
<navigator class="d-i-b" url="/pages/privacy/index?type=2" hover-class='none'>
<text>《xxxxxx》</text>
</navigator>
onLoad(options) {
if (options.type == 2) {
this.setData({
title:'用户协议'
})
}
console.log('options:',options)
}
wx.navigateTo({
url: '/b页面',
success: (res)=> {
res.eventChannel.emit('acceptDataFromOpenerPage', { data: parmas })//参数名字随便起,前后页面对应上即可
)
parmas:说明如下 let parmas = { levelIds: [], //ios 手机不支持数组格式, 可以转成 [].join('、') obj: {} , //ios 手机不支持对象格式,可以转成 json 字符串 pageSize: 20, }
onLoad(options) {
const eventChannel = this.getOpenerEventChannel()
eventChannel.on('acceptDataFromOpenerPage', (data)=> {
//对发送过来的数据进行处理
console.log('acceptDataFromOpenerPage:',data)
})
}
注意:let arr = [] arr.toString().replaceAll(',', '、'), //arr 是空数组会报错
page{
padding-bottom: calc(80px + env(safe-area-inset-bottom))
}
.notice-wrap{
overflow-y: scroll;
height: 100vh;
}
这样不能用微信自带方法监听滚动条
<scroll-view scroll-y="true" style="height:774px">
你需要滚动的内容
</scroll-view >
"rendererOptions": {
"skyline": {
"defaultDisplayBlock": true
}
}
<page-meta page-style="{{ showPopup? 'overflow: hidden;' :''}}">
<view>不能滚动的内容</view>
</page-meta>
app.json
"useExtendedLib": {
"weui": true
}
{
"lazyCodeLoading": "requiredComponents"
}
{
"initialRenderingCache": "static" //dynamic 在初始渲染缓存中添加动态内容
}
{
"window": {
"initialRenderingCache": "static"
}
}
{
"initialRenderingCache": "dynamic" //在初始渲染缓存中添加动态内容
}
Page({
data: {
loading: true
},
onReady: function() {
this.setInitialRenderingCache({
loadingHint: '正在加载' // 这一部分数据将被应用于界面上,相当于在初始 data 基础上额外进行一次 setData
})
}
})
onPageScroll: function(t) {
if(t.scrollTop >= 180){
wx.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#ffffff'
})
app.fadeInOut(this,'fadeAni',1)
}else{
wx.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: '#ffffff'
})
app.fadeInOut(this,'fadeAni',0)
}
}
<navigation id='Navigation' show-search='{{showSearch}}' class="fix-top" animation="{{fadeAni}}"></navigation>
wx.switchTab({
url: '/index'
})
wx.navigateBack({
delta: 1, //上一页
fail(e) {
wx.switchTab({
url: '/pages/grouponList/main'
})
}
})
"window": {
"navigationStyle": "custom",
"navigationBarTextStyle": "black"
},
https://cloud.tencent.com/developer/article/2244976
user-select 属性只能在 text 上使用有效
<rich-text user-select nodes="{{htmlSnip}}"></rich-text>
或者
<text user-select>微信小程序</text>
<button open-type='share' type="warn">分享</button>
<button class='longSave' bindtap='longSave' type="primary">保存到相册</button>
longSave:function(){
wx.showLoading({
title: '请稍等......',
})
wxSaveImageToPhotosAlbum({
filePath:this.data.imagePath
}).then(res => {
wx.hideLoading()
wx.showToast({
title: '已保存到相册',
})
})
}
wx.downloadFile({
url: 'https://res.wx.qq.com/wxdoc/dist/assets/img/demo.ef5c5bef.jpg',
success: (res) => {
wx.showShareImageMenu({
path: res.tempFilePath
})
}
})
clickSign:debounce(function() {
let that = this
console.log(11111,this)
},300),
https://blog.csdn.net/ke_sin/article/details/106578236
<input confirm-type="search" bindconfirm="startSearch"></input>
search 右下角按钮会变为“搜索”
send 右下角按钮会变为“发送”
next 右下角按钮会变为“下一个”
go 右下角按钮会变为“前往”
done 右下角按钮会变为“完成”
<button class="share_list_button" open-type="share">点击按钮分享</button>
onShareAppMessage(res) {
console.log('分享只有在手机上才能看到这个打印:',res.target)
return {
title: '自定义转发标题',
path: '/page/user?id=123'
}
},
70 为固定输入框的盒子高度
<view class="input flex-none" style="height:{{keyboardHeight + 70|| 70}}px">
<input bind:focus="onInputFocus" adjust-position="{{false}}" bind:blur="onInputBlur" placeholder="222" />
</view>
onInputFocus(e) {
if (e.detail.height) {
this.setData({
keyboardHeight: e.detail.height
})
}
},
onInputBlur() {
this.setData({
keyboardHeight: 0
})
},
<view class="row">
<view class="col">1</view>
<view class="col">2</view>
</view>
.row{
overflow: hidden;
column-count: 2; //每行展示的个数
column-gap: 2px;//间距
width: 100%;
}
.col{
width: 95%;
display: inline-block;
background: #fefefe;
border: 2px solid #fcfcfc;
box-shadow: 0px 2px 2px rgba(34, 25, 25, 0.4);
margin: 5px 2px 2px 2px;
padding: 1px;
padding-bottom: 5px;
transition: opacity .4s ease-in-out;
}
wx.downloadFile({
url: 'https://.../XXX.pdf', //要预览的 PDF 的地址
success: function (res) {
if (res.statusCode === 200) { //成功
var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
wx.openDocument({
fileType: 'pdf', // 文件类型
filePath: Path, //要打开的文件路径
success: function (res) {
console.log('打开 PDF 成功');
}
})
}
},
fail: function (err) {
console.log(err); //失败
}
})
[文档](https://developers.weixin.qq.com/miniprogram/dev/component/rich-text.html)
<rich-text nodes="{{htmlSnip}}"></rich-text>
// 模拟接口取到的内容
const htmlSnip =
`<div class="div_class">
<h1>Title</h1>
<p class="p">
Life is <i>like</i> a box of
<b> chocolates</b>.
</p>
<img src="https://p3-passport.byteimg.com/img/user-avatar/d5697ed6a5a9481b9fcfc0dd65b5c08f~100x100.awebp" >
</div>
`
Page({
data: {
htmlSnip:htmlSnip
},
onReady() {
this.addBarrage()
},
onLoad(){
// 给字符串中的所有img设置样式
let replaceImgStyle = htmlSnip.replace('<img ', '<img style="max-width:100%;height:auto;display:block;margin:10px 0;"')
this.setData({
htmlSnip: replaceImgStyle
})
}
})
Page({
goBackPage(e) {
let pages = getCurrentPages();//获取page
let prevPage = pages[pages.length-2];//上一个页面(父页面)
console.log('prevPage',prevPage)
//直接调用上一个页面的setData()方法,把数据存到上一个页面中去,oneselfAddress此参数必须在上一页面中的data声明定义。否则传递失败。
prevPage.setData({
oneselfAddress:'hahah'
})
wx.navigateBack({
delta: 1
})
}
})
onShow() {
console.log('onShow',this.data.oneselfAddress)
let pages = getCurrentPages();
let currPages = pages[pages.length-1]//当前页面
console.log('接收自提地址',currPages)
},
goNextPage() {
wx.redirectTo({
url: `/pages/sun?taskStudentId=${this.data.playObj.id}`,
})
}
goNextPage() {
wx.redirectTo({
url: `/pages/father?taskStudentId=${this.data.playObj.id}`,
})
}