這篇文章給大家分享的是有關(guān)微信小程序如何制作小組件的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

微信小程序 制作小組件
對(duì)于我們?nèi)粘V幸恍┕驳臇|西可以封裝成組件,然后在各個(gè)頁(yè)面使用。對(duì)于小程序,我們也可以封裝我們需要的一些公共的東西。
這里我們講解一個(gè)小插件。

如上圖所示,一個(gè)小插件,單擊是展開(kāi),在單擊關(guān)閉的時(shí)候,按鈕關(guān)閉。
頁(yè)面的WXML (APP.wxml)
<template name="widget-dialog-iconList">
<view class="com-widget-iconList {{close==1?'hideImg':''}}" style="display:flex;flex-direction:row;">
<view style="display:flex;flex-direction:row;">
<view class="left-icon" style="display:flex;flex-direction:row;">
<view class="left-circle"></view>
<image class="icon1" src="http://m.dev.vd.cn/static/xcx/v1/goo/md_logo.png"></image>
</view>
<view class="middle_icon " style="display:flex;flex-direction:row;">
<navigator url="../tua/home">
<view class="section1">
<view><image class="icon2" src="http://m.dev.vd.cn/static/xcx/v1/goo/firsticon.png"></image></view>
<view class="text">首頁(yè)</view>
</view>
</navigator>
<navigator url="../ord/list">
<view class="section2">
<view><image class="icon2" src="http://m.dev.vd.cn/static/xcx/v1/goo/orderIcon.png"></image></view>
<view class="text">訂單</view>
</view>
</navigator>
<navigator url="../usr/center">
<view class="section3">
<view><image class="icon3" src="http://m.dev.vd.cn/static/xcx/v1/goo/myself.png"></image></view>
<view class="text">我的</view>
</view>
</navigator>
<view class="right-icon" style="display:flex;flex-direction:row;">
<image class="iconright" src="http://m.dev.vd.cn/static/xcx/v1/goo/delAllIcon.png" bindtap="closeAllIcon"></image>
</view>
</view>
</view>
</view>
<view class="iconOnly {{close==0?'hideImg':''}}">
<image class="iconOnlyPic" src="http://m.dev.vd.cn/static/xcx/v1/goo/md_logo.png" bindtap="showAllIcon"></image>
</view>
</template>這里主要是插件的壓面展示效果,都寫(xiě)在<template>標(biāo)簽里面就可以了。
頁(yè)面的JS (APP.js)
var iconList = {}; //設(shè)置一個(gè)對(duì)象名字存放數(shù)據(jù)
iconList.Wdg= {
//存放要給VIEW層的頁(yè)面數(shù)據(jù),closeAllIcon ,showAllIcon 是對(duì)應(yīng)的方法
data: {
index: 0,
close:0
},
closeAllIcon: function(e){
this.setData({
close:1
})
},
showAllIcon :function(e){
this.setData({
close:0
})
}
};
module.exports=iconList //將接口的進(jìn)行暴露,方便在外面調(diào)用接下來(lái)封裝好了,就是該怎么使用了。
在需要的WXML頁(yè)面:
通過(guò) 引入斤頁(yè)面,再通過(guò)
<template is="widget-dialog-iconList" data="{{你要傳到頁(yè)面的數(shù)據(jù)}}"></template>進(jìn)行使用。
在需要的WXML頁(yè)面:
通過(guò)var iconList = require('../wdg/iconList');引入對(duì)應(yīng)的JS
var util= require('../../util/util');
var Page = new util.Page({
Wdgs: [iconList.Wdg]
});引入對(duì)應(yīng)文件。
感謝各位的閱讀!關(guān)于“微信小程序如何制作小組件”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
文章名稱(chēng):微信小程序如何制作小組件-創(chuàng)新互聯(lián)
分享路徑:http://chinadenli.net/article34/ddhhpe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站策劃、靜態(tài)網(wǎng)站、網(wǎng)站排名、App開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容