微信小程序开发小技巧
1、轮播组件
2、用if标签控制内容的输出显示
新品
热销
推荐
3、组件弹性布局,常用于一行有多个时,平均分配宽度
新品55
销量555:{{item.shiyong}}
4、打印输出调试信息
console.log('23432')
5、图片、组建透明度设置
div
{
opacity:0.5;
}
//图片透明度
// opacity :规定不透明度。从 0.0 (完全透明)到 1.0(完全不透明)
6、弹出提示框
selectByItemName: function () {
var that = this;
if (!that.data.inputKey) {
wx.showToast({
title: '请输入关键字',
icon:'loading',
duration:2000,
})
return ;
}
// 隐藏消息提示框:
wx.showToast({
title: '加载中' ,
icon: 'loading' ,
duration: 10000
})
// 2s 后关闭提示框
setTimeout( function (){
wx.hideToast()
},2000)
7、轮播图中图片绑定点击事件
//多个轮播图绑定同一事件,通过id或index值区分
1) bindtap="itemClick" id="{{index}}" 绑定的函数实现:
itemClick: function (event) {
console.log(event)
var index = event.target.id
},
2)wx:bindtap="itemClick" data-index="{{index}}" 绑定的函数实现方式:
itemClick: function (event) {
console.log(event)
var index = event.target.dataset.index
},
8、显示模态对话框
wx.showModal({
title: '提示',
content: '这是一个模态弹窗',
success: function(res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
})
(持续更新中.....)
网站栏目:
微信小程序开发小技巧
网页路径:
http://tjjierui.cn/view/108977.html