微信小程序?qū)崿F(xiàn)點(diǎn)擊出現(xiàn)彈窗
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)點(diǎn)擊出現(xiàn)彈窗的具體代碼,供大家參考,具體內(nèi)容如下
1.現(xiàn)在page文件里面定義一個(gè)dh的文件,然后在component定義一個(gè)可復(fù)用的組件為dislog
然后在dh的json文件中引入這個(gè)組件
{ ? "usingComponents": { ? ? "dialog":"../../component/dialog/index" ? ??? ??? ? } ? ? }
2.dh中.js文件
// pages/dh/index.js Page({ ? data: { ? ? status:false ? }, ? handleTap(){ ? ? this.setData({ ? ? ? status:true ? ? }) ? }, ? handlecancel(){ ? ? this.setData({ ? ? ? status:false ? ? }) ? }, ? handleConfirm(){ ? ? this.setData({ ? ? ? status:false ? ? }) ? } })
.wxml文件中
<dialog title="警告" status="{{status}}" bind:cancel='handlecancel' bind:confirm="handleConfirm" content='啦啦啦我也不知道這什么哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈'> ? <image src='//gw.alicdn.com/imgextra/i1/O1CN016q4k5T1IPNCZM2RTx_!!6000000000885-0-tps-640-260.jpg_Q75.jpg'></image> </dialog> <view bindtap='handleTap' class='show'>顯示</view>
.wxss文件
/* pages/dh/index.wxss */ .show{ ? /* width:100%; ? height:100vh; */ ? width:200rpx; ? height:140rpx; ? background:#ccc; ? border-radius:20rpx; ? color:#fff; ? text-align:center; ? line-height:140rpx; ? font-size:40rpx; ? margin:0 auto; ? margin-top:470rpx; }
在組件中dialog文件中
index.js文件
// component/dialog/index.js Component({ ? /** ? ?* 組件的屬性列表 ? ?*/ ? properties: { ? ? title:{ ? ? ? type:String, ? ? ? value:"標(biāo)題" ? ? }, ? ? content:String, ? ? status:{ ? ? ? type:Boolean, ? ? ? value:false, ? ? } ? }, ? /** ? ?* 組件的初始數(shù)據(jù) ? ?*/ ? data: { ? }, ? /** ? ?* 組件的方法列表 ? ?*/ ? methods: { ? ? handleCancel(){ ? ? ? this.triggerEvent("cancel") ? ? }, ? ? handleConfirm(){ ? ? ? // this.triggerEvent('confirm') ? ? ? ? this.triggerEvent('confirm') ? ? } ? } })
wxml文件
<view class="mask" wx:if="{{status}}"> ? <view class="dialog"> ? ? <view class="dialog-header"> ? ? ? ? {{title}} ? ? </view> ? ? <view class="dialog-body"> ? ? ? <view wx:if="{{content}}" class='content'>{{content}}</view> ? ? ? <slot></slot> ? ? </view> ? ? <view class="dialog-footer"> ? ? ? <view class="dialog-btn" bindtap='handleCancel'>取消</view> ? ? ? <view class="dialog-btn" bindtap='handleConfirm'>確認(rèn)</view> ? ? </view> ? </view> </view>
wxss文件
.mask{ ? position:fixed; ? top:0; ? left:0; ? right:0; ? bottom:0; ? background-color:rgb(0,0,0,0.3); ? display:flex; ? align-items: center; ? justify-content:center; } .dialog{ ? width:600rpx; ? height:auto; ? background:#fff; ? border-radius:30rpx; } .dialog-header{ ? padding:30rpx 0; ? text-align:center; ? font-size:36rpx; } .dialog-footer{ ? display:flex; } .dialog-btn{ ? flex:1; ? text-align:center; ? padding:40rpx 0; ? border-top:1rpx solid #eee; } .dialog-btn:first-child{ ? border-right:1rpx solid #eee; } .dialog-body{ ? padding:30rpx; } .content { ? text-indent: 72rpx; ? color:#333; } .dialog-body image{ ? width:100%; }
這樣就可以實(shí)現(xiàn)一個(gè)簡(jiǎn)單的點(diǎn)擊出現(xiàn)彈窗的效果。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS實(shí)現(xiàn)重新加載當(dāng)前頁(yè)面
本文主要介紹用JavaScript刷新上級(jí)頁(yè)面和當(dāng)前頁(yè)面。附上具體實(shí)例代碼。需要的朋友可以參考下2016-11-11純JavaScript實(shí)現(xiàn)獲取onclick、onchange等事件的值
這篇文章主要介紹了JavaScript獲取onclick、onchange等事件的值的方法,需要的朋友可以參考下2014-12-12性能優(yōu)化篇之Webpack構(gòu)建代碼質(zhì)量壓縮的建議
這篇文章主要介紹了性能優(yōu)化篇之Webpack構(gòu)建代碼質(zhì)量壓縮的建議,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-04-04微信小程序?qū)崿F(xiàn)2048小游戲的詳細(xì)過(guò)程
這篇文章主要給大家介紹了關(guān)于微信小程序?qū)崿F(xiàn)2048小游戲的相關(guān)資料,文中將實(shí)現(xiàn)的代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用微信小程序具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2021-09-09JavaScript中的boolean布爾值使用學(xué)習(xí)及相關(guān)技巧講解
JavaScript中的boolean布爾值使用學(xué)習(xí)及相關(guān)技巧講解,特別是Boolean的用法以及適用!!將truthy或falsy值轉(zhuǎn)換為布爾值的用法非常巧妙,需要的朋友可以參考下2016-05-05