toast.uvue 2.8 KB
Newer Older
Y
yurj26 已提交
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 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
<template>
    <view>
        <page-head :title="title"></page-head>
        <view class="uni-padding-wrap">
            <view class="uni-btn-v">
                <button class="uni-btn" type="default" @tap="toast1Tap">点击弹出默认toast</button>
                <button class="uni-btn" type="default" @tap="toast2Tap">点击弹出设置duration的toast</button>
                <button class="uni-btn" type="default" @tap="toast3Tap">点击弹出显示loading的toast</button>
                <!-- #ifndef MP-ALIPAY -->
                <button class="uni-btn" type="default" @tap="toast4Tap">点击弹出显示自定义图片的toast</button>
                <!-- #endif -->
                <!-- #ifdef APP-PLUS -->
                <button class="uni-btn" type="default" @tap="toast5Tap">点击显示无图标的居底toast</button>
                <!-- #endif -->
                <button class="uni-btn" type="default" @tap="hideToast">点击隐藏toast</button>
            </view>
        </view>
    </view>
</template>
<script lang="ts">
    export default {
        data() {
            return {
                title: 'toast',
                _showTimer: 0
            }
        },
        // #ifdef MP-ALIPAY
        onUnload() {
            clearTimeout(this._showTimer);
        },
        // #endif
        methods: {
            toast1Tap: function () {
                uni.showToast({
                    title: "默认"
                })
            },
            toast2Tap: function () {
                uni.showToast({
                    title: "duration 3000",
                    duration: 3000
                })
            },
            toast3Tap: function () {
                uni.showToast({
                    title: "loading",
                    icon: "loading",
                    duration: 5000
                })
                // #ifdef MP-ALIPAY
                this._showTimer = setTimeout(() => {
                    // icon 是 loading 时,showToast 实际执行的是 showLoading
                    my.hideLoading()
                    // 执行完所有代码再清除定时器
                    clearTimeout(this._showTimer);
                }, 3000)
                // #endif

            },
            toast4Tap: function () {
                uni.showToast({
                    title: "logo",
                    image: "/static/uni.png"
                })
            },
            // #ifdef APP-PLUS
            toast5Tap: function () {
                uni.showToast({
                    title: "显示一段轻提示",
                    position: 'bottom'
                })
            },
            // #endif
            hideToast: function () {
                uni.hideToast()
            }
        }
    }
</script>