toast.uvue 3.5 KB
Newer Older
Y
yurj26 已提交
1
<template>
Y
yurj26 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  <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 -->
        <!-- #ifdef APP-PLUS -->
        <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>
Y
yurj26 已提交
19
    </view>
Y
yurj26 已提交
20
  </view>
Y
yurj26 已提交
21
</template>
Y
yurj26 已提交
22
<script lang="uts">
Y
yurj26 已提交
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 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 100 101 102 103 104 105 106 107
  export default {
    data() {
      return {
        title: 'toast',
        exeRet: ''
      }
    },
    methods: {
      toast1Tap: function () {
        uni.showToast({
          title: "默认",
          success: function (res) {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: function (res) {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      toastTapIconError: function () {
        uni.showToast({
          title: "默认",
          icon: 'error',
          success: function (res) {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: function (res) {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      toast2Tap: function () {
        uni.showToast({
          title: "duration 3000",
          duration: 3000,
          success: function (res) {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: function (res) {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      toast3Tap: function () {
        uni.showToast({
          title: "loading",
          icon: "loading",
          duration: 5000,
          success: function (res) {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: function (res) {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      toast4Tap: function () {
        uni.showToast({
          title: "logo",
          image: "/static/uni.png",
          success: function (res) {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: function (res) {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      // #ifdef APP-PLUS
      toast5Tap: function () {
        uni.showToast({
          title: "显示一段轻提示",
          position: 'bottom',
          success: function (res) {
            this.exeRet = "success:" + JSON.stringify(res) + new Date()
          },
          fail: function (res) {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      // #endif
      hideToast: function () {
        uni.hideToast()
      }
Y
yurj26 已提交
108
    }
Y
yurj26 已提交
109 110
  }
</script>