1. 程式人生 > >微信小程式-訊息提示框

微信小程式-訊息提示框

微信小程式開發中toast也是重要的訊息提示方式.

提示框:

wx.showToast(OBJECT)

顯示訊息提示框

OBJECT引數說明:

示例程式碼:

?

1

2

3

4

5

wx.showToast({

title:'成功',

icon:'success',

duration: 2000

})

wx.hideToast()

隱藏訊息提示框

?

1

2

3

4

5

6

7

8

9

wx.showToast({

title:'載入中',

icon:'loading',

duration: 10000

})

setTimeout(function(){

wx.hideToast()

},2000)

wx.showModal(OBJECT)

顯示模態彈窗

OBJECT引數說明:

示例程式碼:

?

1

2

3

4

5

6

7

8

9

wx.showModal({

title:'提示',

content:'這是一個模態彈窗',

success:function(res) {

if(res.confirm) {

console.log('使用者點選確定')

}

}

})

wx.showActionSheet(OBJECT)

顯示操作選單

OBJECT引數說明:

success返回引數說明:

示例程式碼:

?

1

2

3

4

5

6

7

8

wx.showActionSheet({

itemList: ['A','B', 'C'],

success:

function(res) {

if(!res.cancel) {

console.log(res.tapIndex)

}

}

})

設定導航條

<view>提示:{{tip}}</view>

<button type="default" bindtap="showModal">點選我彈出modal對話方塊</button>

<view>

<modal title="modal對話方塊" hidden="{{modalHidden}}" confirm-text="確定" cancel-text="取消"

bindconfirm="modalBindaconfirm" bindcancel="modalBindcancel">您好,我是modal對話方塊</modal>

</view>

Page({

data:{

// text:"這是一個頁面"

tip:'',

buttonDisabled:false,

modalHidden:true,

show:false

},

showModal:function(){

this.setData({

modalHidden:!this.data.modalHidden

})

},

modalBindaconfirm:function(){

this.setData({

modalHidden:!this.data.modalHidden,

show:!this.data.show,

tip:'您點選了【確認】按鈕!',

buttonDisabled:!this.data.buttonDisabled

})

},

modalBindcancel:function(){

this.setData({

modalHidden:!this.data.modalHidden,

tip:'您點選了【取消】按鈕!'

})

}

})

wx.setNavigationBarTitle(OBJECT)

動態設定當前頁面的標題。

OBJECT引數說明:

示例程式碼:

?

1

2

3

wx.setNavigationBarTitle({

title:'當前頁面'

})

wx.showNavigationBarLoading()

在當前頁面顯示導航條載入動畫。

wx.hideNavigationBarLoading()

隱藏導航條載入動畫。

頁面跳轉:

wx.navigateTo(OBJECT)

保留當前頁面,跳轉到應用內的某個頁面,使用wx.navigateBack可以返回到原頁面。

OBJECT引數說明:

示例程式碼:

?

1

2

3

wx.navigateTo({

url:'test?id=1'

})

?

1

2

3

4

5

6

//test.js

Page({

onLoad:function(option){

console.log(option.query)

}

})

注意:為了不讓使用者在使用小程式時造成困擾,我們規定頁面路徑只能是五層,請儘量避免多層級的互動方式。

wx.redirectTo(OBJECT)

關閉當前頁面,跳轉到應用內的某個頁面。

OBJECT引數說明:

示例程式碼:

?

1

2

3

wx.redirectTo({

url:'test?id=1'

})

wx.navigateBack(OBJECT)

關閉當前頁面,返回上一頁面或多級頁面。可通過 getCurrentPages()) 獲取當前的頁面棧,決定需要返回幾層。

OBJECT引數說明:

 動畫:

wx.createAnimation(OBJECT)

建立一個動畫例項animation。呼叫例項的方法來描述動畫。最後通過動畫例項的export方法匯出動畫資料傳遞給元件的animation屬性。

注意: export 方法每次呼叫後會清掉之前的動畫操作

OBJECT引數說明:

?

1

2

3

4

5

6

var animation = wx.createAnimation({

transformOrigin:"50% 50%",

duration: 1000,

timingFunction:"ease",

delay: 0

})

animation

動畫例項可以呼叫以下方法來描述動畫,呼叫結束後會返回自身,支援鏈式呼叫的寫法。

樣式:

 旋轉:

 縮放:

 偏移:

 傾斜:

 矩陣變形:

 動畫佇列

呼叫動畫操作方法後要呼叫 step() 來表示一組動畫完成,可以在一組動畫中呼叫任意多個動畫方法,一組動畫中的所有動畫會同時開始,一組動畫完成後才會進行下一組動畫。step 可以傳入一個跟 wx.createAnimation() 一樣的配置引數用於指定當前組動畫的配置。

示例:

?

1

<viewanimation="{{animationData}}"style="background:red;height:100rpx;width:100rpx"></view>

?

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

43

44

45

46

47

48

49

Page({

data: {

animationData: {}

},

onShow:function(){

varanimation = wx.createAnimation({

duration: 1000,

timingFunction:'ease',

})

this.animation = animation

animation.scale(2,2).rotate(45).step()

this.setData({

animationData:animation.export()

})

setTimeout(function() {

animation.translate(30).step()

this.setData({

animationData:animation.export()

})

}.bind(this), 1000)

},

rotateAndScale:function () {

// 旋轉同時放大

this.animation.rotate(45).scale(2, 2).step()

this.setData({

animationData:this.animation.export()

})

},

rotateThenScale:function () {

// 先旋轉後放大

this.animation.rotate(45).step()

this.animation.scale(2, 2).step()

this.setData({

animationData:this.animation.export()

})

},

rotateAndScaleThenTranslate:function () {

// 先旋轉同時放大,然後平移

this.animation.rotate(45).scale(2, 2).step()

this.animation.translate(100, 100).step({ duration: 1000 })

this.setData({

animationData:this.animation.export()

})

}

})

wx.hideKeyboard()

收起鍵盤。

wx.stopPullDownRefresh()

停止當前頁面下拉重新整理。詳見 頁面相關事件處理函式

--------------------- 本文來自 東邊的小山 的CSDN 部落格 ,全文地址請點選:https://blog.csdn.net/yelin042/article/details/72287164?utm_source=copy