微信小程序開發(fā)小技巧

2021-04-20    分類: 微信小程序

1、輪播組件

<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
<block wx:for="{{imgUrls}}">
<swiper-item>
<image src="{{item.photo}}" class="slide-image" width="100%" height="200" />
</swiper-item>
</block>
</swiper>

2、用if標(biāo)簽控制內(nèi)容的輸出顯示

<view class="gmxx" style="font-size:28rpx;width:30%">
<text wx:if="item.is_show==1">新品</text>
<text wx:elif="item.is_hot==1">熱銷</text>
<text wx:else>推薦</text>
</view>

3、組件彈性布局,常用于一行有多個(gè)<view>時(shí),平均分配寬度

<view style="display:flex; flex-direction:row; justify-content:space-around; margin:0rpx; line-height:50rpx; color:#999">
<view class="" style="font-size:28rpx; padding-right:70rpx; margin:0rpx;">
<text>新品55</text>
</view>
<view class="" style="font-size:28rpx;">銷量555:{{item.shiyong}}</view>
</view>

4、打印輸出調(diào)試信息

console.log('23432')

5、圖片、組建透明度設(shè)置

div
{
opacity:0.5;
}
//圖片透明度
<image style="opacity:0.5" src="1.png"></image>
// opacity :規(guī)定不透明度。從 0.0 (完全透明)到 1.0(完全不透明)

6、彈出提示框

selectByItemName: function () {
var that = this;
if (!that.data.inputKey) {
wx.showToast({
title: '請(qǐng)輸入關(guān)鍵字',
icon:'loading',
duration:2000,
})
return ;
}
// 隱藏消息提示框:

wx.showToast({
title: '加載中' ,
icon: 'loading' ,
duration: 10000
})
// 2s 后關(guān)閉提示框
setTimeout( function (){
wx.hideToast()
},2000)

7、輪播圖中圖片綁定點(diǎn)擊事件

//多個(gè)輪播圖綁定同一事件,通過id或index值區(qū)分
1) bindtap="itemClick" id="{{index}}" 綁定的函數(shù)實(shí)現(xiàn):
itemClick: function (event) {
console.log(event)
var index = event.target.id
},
2)wx:bindtap="itemClick" data-index="{{index}}" 綁定的函數(shù)實(shí)現(xiàn)方式:

itemClick: function (event) {
console.log(event)
var index = event.target.dataset.index
},

8、顯示模態(tài)對(duì)話框

wx.showModal({
title: '提示',
content: '這是一個(gè)模態(tài)彈窗',
success: function(res) {
if (res.confirm) {
console.log('用戶點(diǎn)擊確定')
}
}
})

(持續(xù)更新中.....)

本文名稱:微信小程序開發(fā)小技巧
文章鏈接:http://www.muchs.cn/news27/108977.html

網(wǎng)站建設(shè)、網(wǎng)絡(luò)推廣公司-創(chuàng)新互聯(lián),是專注品牌與效果的網(wǎng)站制作,網(wǎng)絡(luò)營(yíng)銷seo公司;服務(wù)項(xiàng)目有小程序開發(fā)、微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)