modal彈出框遮罩層可實現提示信息、驗證碼等功能
然而在官方文檔已經刪除了modal的頁面,說要廢棄modal
就個人而言modal組件無法被wx.showmodal完全替代。大家都知道小程序的wxml的組件可以通過改變js的值實現重新渲染,而接口是無法實現的
有同感的也不止博主一個人
官方18-5-13的建議要實現此類功能也是用modal
屬性
說下遮罩層實現,通過改變modal的hidden屬性來控制是否顯示,通過監聽confirm方法來確認提交,通過bindinput來監聽modal內表單組件內容
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
page({ data: { hiddenmodal1: true , hiddenmodal2: true , input: null }, showmodal1: function (e){ this .setdata({hiddenmodal1: false }) }, model1confirm: function (e){ this .setdata({ hiddenmodal1: true }) wx.showtoast({ title: '我覺得ok' , }) }, model1cancel: function (e){ this .setdata({ hiddenmodal1: true }) wx.showtoast({ title: '我覺得不行' , }) }, input: function (e){ this .setdata({input:e.detail.value}) }, showmodal2: function (e) { this .setdata({ hiddenmodal2: false }) }, model2confirm: function (e) { this .setdata({ hiddenmodal2: true }) wx.showtoast({ title: '確定' + this .data.input, icon: 'none' }) }, model2cancel: function (e) { this .setdata({ hiddenmodal2: true }) wx.showtoast({ title: '取消' + this .data.input, icon: 'none' }) } }) |
wxml
1
2
3
4
5
6
7
8
|
< button type = "primary" bindtap = 'showmodal1' >彈出提示modal</ button > < button type = "default" bindtap = 'showmodal2' >彈出帶文本框的modal</ button > < modal hidden = "{{hiddenmodal1}}" title = "提示modal" confirm-text = "是" cancel-text = "否" bindconfirm = "model1confirm" bindcancel = "model1cancel" > modal是真的好用 </ modal > < modal hidden = "{{hiddenmodal2}}" title = "文本框的modal" confirm-text = "提交" cancel-text = "取消" bindconfirm = "model2confirm" bindcancel = "model2cancel" > < input placeholder = '請輸入內容' bindinput = 'input' /> </ modal > |
到此這篇關于微信小程序實現modal彈出框遮罩層組件(可帶文本框)的文章就介紹到這了,更多相關微信小程序modal彈出框遮罩層組件內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/xjc8289555/article/details/80327267