| 主機參考:VPS測評參考推薦/專注分享VPS服務器優惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務,查看詳情! |
| 我們發布的部分優惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作 |
微信小程序存在于按鈕組件中。微信小程序本來就存在于按鈕組件中,樣式也不難看,還有很多擴展屬性。只要看文檔,邊讀邊試,就很容易構造出一個理想的按鈕Button。微信小程序按鈕入口。但是,在某些情況下,可能會覺得原生按鈕組件的配置過于復雜或者不符合當前的要求,因此可能需要自定義一個按鈕組件。
好,我們開始吧。比如我就想要這種效果。
有五種不同的顏色
有三種不同的尺寸。
有鏤空效果。
你可以切魚片。
可以禁用。
您可以設置圖標。
代碼的第一步是創建一個組件。首先,打開編輯器。這里打開微信開發者工具,然后創建一個這樣的組件。

我這里用了Vscode然后用的少了,easyless插件自動編譯成wxss風格的少了。
第二步:要注意控制結構和風格結構:
文本應該顯示在中間,所以在這里使用flex布局可能會很方便。
圖標位置需要保留;如果未設置,則不會顯示
您需要設置背景顏色控制選項。
注意對應的結構和風格。
ltbutton class = PM-按鈕PM-按鈕--{ { size } } PM-按鈕--{{type}} {{plain?'PM-button --plain # 39;:''} } { {圓?'PM-按鈕--圓形 # 39;:''} } { {禁用?'PM-按鈕--禁用 # 39;:''} } style = { { cStyle } } bindtap = 單擊處理程序 gt ltPM-icon icon = ;{ { icon } } color = { { iconColor } } size = { { iconSize } } wx:if = ;{ { icon } } gt lt/PM-icon gt; ltslot/>; lt/button gt;. PM-button { border -radius:0;font -體重:正常;顯示器:flexflex -flow:row nowrap;justify -內容:居中;align -項:居中;white -space:nowrap;} . PM-按鈕:不是([size = # 39;迷你 # 39;]) {寬度:0;}.pm-button--normal {寬度:80px!重要;高度:40pxfont -大小:16px} . PM-button --normal . PM-button --round { border -radius:40px;}.pm-button--small {寬度:60px!重要;高度:30pxfont -size:14px;} . PM-button --small . PM-button --round { border -radius:30px;} . PM-button --mini { width:40px!重要;高度:20pxfont -size:12px;} . PM-button --mini . PM-button --round { border -radius:20px;} . PM-button --原色{ background -color:# 1989 fa;邊框:1px純色# 1989fa顏色:白色;} . PM-button --primary . PM-button --plain { color:# 1989 fa;} . PM-button --成功{ background -color:# 07c 160;邊框:1px純色# 07c160顏色:白色;} . PM-button --success . PM-button --plain { color:# 07c 160;} . PM-button --危險{ background -color:# ee0a 24;邊框:1px純色# ee0a24顏色:白色;} . PM-button --danger . PM-button --plain { color:# ee0a 24;} . PM-button --警告{ background -color:# ff 976 a;邊框:1px純色# ff976a顏色:白色;} . PM-button --warning . PM-button --plain { color:# ff 976 a;} . PM-button --默認{ background -color:# ffffff;邊框:1px solid # ebedf0顏色:黑色;} . PM-button --初級:主動,. PM-button --成功:主動,. PM-button --危險:主動,. PM-button --警告:主動,. PM-button --默認:主動{不透明度:0.8;} . PM-button --default:active { background -color:# ebedf 0;} . PM-button --plain { background -color:透明;} . PM-button --plain:active { opacity:1!重要;background -color:# ebedf 0;} . PM-button --禁用{不透明度:0.6;} . PM-button --禁用:活動{不透明度:0.6!重要;} . PM-button --disabled . PM-button --plain:活動,. PM-button --disabled . PM-button --default:活動{ background-color:透明;}第三步,邏輯處理組件的屬性列表({/* * * Component */properties:{ size:{ type:string,value: # 39;正常 # 39;},類型:{ type: String,value: # 39;初級 # 39;},plain: Boolean,disabled: Boolean,round: Boolean,cStyle: String,icon: String,iconColor: String,iconSize: String },/* * *組件的方法列表*/ methods: {clickHandler() {!this . data . disabled ; this . trigger event( # 39;點擊 # 39;,{}}})推薦教程:《微信小程序》以上是一個微信小程序的按鈕組件的細節。更多請關注主機參考其他相關文章!
這幾篇文章你可能也喜歡:
- 如何在微信系的父母(頁面通信)中實現兒童傳輸參數(微信Mini Program Navigateto傳輸參數)
- 如何操作微信迷你計劃購物中心系統? (使用Mini計劃購物中心的教程)
- 關于如何在Mini程序中創建頁面QR碼的簡要說明(如何為Mini Program Page生成QR碼)
- 簡單分析如何動態創建迷你程序代碼(在微信中更改動態圖像)
- 如何檢查微信系的無線密碼(如何檢查微信小程序的WiFi密碼)
本文由主機參考刊發,轉載請注明:快速實現一個微信小程序的按鈕組件(微信小程序的按鈕是由什么組件實現的) http://www.k2270.com/77063.html
主機參考

















評論前必須登錄!
注冊