VX小程序三

小程序自定義組件使用

第一步:創(chuàng)建自定義組件

 創(chuàng)建compoents目錄,在該目錄下創(chuàng)建要復(fù)用的組件,例如:dialog組件

 其中dialo.js參數(shù)說(shuō)明:

   properties:接收父級(jí)傳遞過(guò)來(lái)的值

     例如:
          properties: {
             title:{
               type:String,
               value:"標(biāo)題"
             },
             content:{
               type:String,
               value:"內(nèi)容"
             },
             cancelText:{
               type:String,
               value:"取消"
             },
             confirmText:{
               type:String,
               value:"確定"
             }

          }

第二步:如何引入組件

例如:在login頁(yè)面中引入dialog組件

在dialog.json中引入

例如:

        {
            "usingComponents":{
                "dialog":"/components/dialog/dialog"
            }
        }

然后再dialog頁(yè)面上使用dialog組件:

    例如:

        <dialog id="dialog"
                title="這是一個(gè)標(biāo)題"
                bind:confirmEvent="_queding"
                bind:cancelEvent="_quxiao"
        ></dialog>

注意:
如何派發(fā)事件: this.triggerEvent('自定義事件名',要傳遞的數(shù)據(jù));

     triggerEvent相當(dāng)于vue的$emit

 例如: this.triggerEvent('confirmEvent',{name:"確定"});

如何監(jiān)聽(tīng)事件:用bind監(jiān)聽(tīng)派發(fā)過(guò)來(lái)的事件 相當(dāng)于vue中的@

       例如:   bind:confirmEvent="_queding"

小程序支持單slot和多slot::與vue類似

參考:https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html

數(shù)據(jù)持久化:

 cookie,H5本地存儲(chǔ)(localstrorage,sessionStorage),webSql
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容