1匆光、wx.showModal() 確認框
title:提示的標題
content:提示的內(nèi)容
success:接口調(diào)用成功的回調(diào)函數(shù)砖茸。回調(diào)函數(shù)中的confirm屬性返回true殴穴,表示點擊的是確定按鈕凉夯,否則是取消按鈕。
?wx.showModal({
??????content:'是否確定刪除',
??????success:({confirm})=>{
????????//confirm返回true采幌,表示點擊的是確定按鈕劲够,否則是取消按鈕
????????if(confirm){
??????}
????})?
2、wx.showToast() 顯示消息提示框
title:提示的內(nèi)容
icon:圖標
duration:消息提示框的顯示時間
mask:是否顯示透明蒙層休傍,防止觸摸穿透
???wx.showToast({
????????title:?'刪除成功',
????????icon:"success",
????????duration:1500,
????????mask:true
???})
封裝方法
模塊化語法有兩種:① commonjs規(guī)范征绎,② es6規(guī)范。
nodejs環(huán)境采用的就是commonjs規(guī)范磨取。采用exports 或 module.exports 導(dǎo)出成員人柿,采用require() 導(dǎo)入成員。
微信小程序支持commonjs規(guī)范忙厌,同時還支持官方的ES6規(guī)范凫岖。ES6規(guī)范采用export 導(dǎo)出成員,采用import 導(dǎo)入成員逢净。
[if !supportLists]1哥放、[endif]封裝方法并導(dǎo)出
將封裝的方法放到util目錄下的js文件中〉粒可以新建js文件甥雕,也可以寫在直接util.js文件中。
(1)確認框方法
//?定義確認框方法胀茵,并導(dǎo)出
export?let?$confirm?=?(content)=>{
??return?new?Promise((resolve)=>{
????wx.showModal({
??????content,
??????success:({confirm})=>{
????????if(confirm){
??????????resolve()
????????}
??????}
????})
??})
}
(2)消息框方法
//?定義消息框方法社露,并導(dǎo)出
export?let?$msg?=?(title,icon='success',duration=1500)=>{
??wx.showToast({
????title,
????icon,
????duration,
????mask:true
??})
}
(3)獲取事件參數(shù)的方法
export?let?$key?=?(e)=>{
??return?e.currentTarget.dataset
}
[if !supportLists]2、[endif]導(dǎo)入方法
import是ES6的導(dǎo)入語句琼娘。
//?導(dǎo)入msg模塊中的指定成員
import?{$msg,$confirm}?from?'../../utils/msg'
[if !supportLists]3峭弟、[endif]將方法注冊給全局對象wx
wx對象是微信小程序的全局對象赁濒,在任何地方都可以使用。
[if !supportLists](1)[endif]注冊語句
wx.$msg?=?$msg
wx.$confirm?=?$confirm
[if !supportLists](2)[endif]在app.js入口文件中導(dǎo)入
注意:注冊給wx對象的方法孟害,需要在app.js文件中導(dǎo)入拒炎,才可使用。
//?導(dǎo)入初始化文件
import?'./utils/index'
[if !supportLists](3)[endif]調(diào)用方法
wx.方法名(參數(shù))
wx.$msg('刪除成功')
[if !supportLists]七挨务、[endif]scroll-view
可滾動視圖區(qū)域击你。使用豎向滾動時,需要給scroll-view一個固定高度谎柄,通過 WXSS 設(shè)置 height丁侄。組件屬性的長度單位默認為px,2.4.0起支持傳入單位(rpx/px)朝巫。
scroll-x:允許橫向滾動鸿摇。
scroll-y:允許縱向滾動。
?<scroll-view?class="left"?scroll-y>??</scroll-view>