toast.uvue 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<template>
  <view>
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap">
      <view class="uni-btn-v">
        <button class="uni-btn-v" type="default" @tap="toast1Tap">点击弹出默认toast</button>
        <button class="uni-btn-v" type="default" @tap="toastTapIconError">点击弹出设置icon的toast</button>
        <button class="uni-btn-v" type="default" @tap="toast2Tap">点击弹出设置duration的toast</button>
        <button class="uni-btn-v" type="default" @tap="toast3Tap">点击弹出显示loading的toast</button>
        <!-- #ifndef MP-ALIPAY -->
        <button class="uni-btn-v" type="default" @tap="toast4Tap">点击弹出显示自定义图片的toast</button>
        <!-- #endif -->
13
        <!-- #ifdef APP-PLUS -->
14 15 16 17 18 19 20 21
        <button class="uni-btn-v" type="default" @tap="toast5Tap">点击显示无图标的居底toast</button>
        <!-- #endif -->
        <button class="uni-btn-v" type="default" @tap="hideToast">点击隐藏toast</button>
      </view>
      <text>{{exeRet}}</text>
    </view>
  </view>
</template>
H
hdx 已提交
22 23

<script>
24 25 26 27 28 29 30
  export default {
    data() {
      return {
        title: 'toast',
        exeRet: ''
      }
    },
H
hdx 已提交
31
    onLoad() {
杜庆泉's avatar
杜庆泉 已提交
32
      uni.showToast({
H
hdx 已提交
33
        title: 'onLoad 调用示例,2秒后消失'
杜庆泉's avatar
杜庆泉 已提交
34
      })
H
hdx 已提交
35
      setTimeout(function () {
杜庆泉's avatar
杜庆泉 已提交
36
        uni.hideToast()
37
      }, 2000);
杜庆泉's avatar
杜庆泉 已提交
38
    },
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    methods: {
      toast1Tap: function () {
        uni.showToast({
          title: "默认",
          success: (res) => {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: (res) => {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      toastTapIconError: function () {
        uni.showToast({
          title: "默认",
          icon: 'error',
          success: (res) => {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: (res) => {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      toast2Tap: function () {
        uni.showToast({
          title: "duration 3000",
          duration: 3000,
          success: (res) => {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: (res) => {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      toast3Tap: function () {
        uni.showToast({
          title: "loading",
          icon: "loading",
          duration: 5000,
          success: (res) => {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: (res) => {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      toast4Tap: function () {
        uni.showToast({
          title: "logo",
          image: "/static/uni.png",
          success: (res) => {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: (res) => {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
100
      // #ifdef APP-PLUS
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
      toast5Tap: function () {
        uni.showToast({
          title: "显示一段轻提示",
          position: 'bottom',
          success: (res) => {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: (res) => {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      // #endif
      hideToast: function () {
        uni.hideToast()
      }
    }
  }
Y
yurj26 已提交
119
</script>