1***@qq.com
1***@qq.com
  • 发布:2024-04-26 13:39
  • 更新:2024-04-26 13:59
  • 阅读:221

uni.showActionSheet 取消按钮触发了 fail 的回调

分类:uni-app

我创建了一个空白项目,并且仅添加了以下代码,这里点击取消按钮出发了 fail的回调函数, 而不是在success中 tapIndex = -1,这个行为是正常的吗

<template>  
    <view class="content">  
            <button @click="test">test</button>  
    </view>  
</template>  

<script>  
    export default {  
        onLoad() {  

        },  
        methods: {  
            test() {  
                uni.showActionSheet({  
                    itemList:["t1", "t2", "t3"],  
                    title: "test",  
                    success: (res) => {  
                        console.log(res);  
                        if(res.tapIndex != -1){  
                            console.log("点击了按钮", res.tapIndex);  
                        }else {  
                            console.log("取消了点击")  
                        }  
                    },  
                    fail: (msg) => {  
                        console.log("系统异常");  
                        console.log(msg)  
                    }  
                })  
            }  
        }  
    }  
</script>  

<style>  
    .content {  
        display: flex;  
        flex-direction: column;  
        align-items: center;  
        justify-content: center;  
    }  

    .logo {  
        height: 200rpx;  
        width: 200rpx;  
        margin-top: 200rpx;  
        margin-left: auto;  
        margin-right: auto;  
        margin-bottom: 50rpx;  
    }  

    .text-area {  
        display: flex;  
        justify-content: center;  
    }  

    .title {  
        font-size: 36rpx;  
        color: #8f8f94;  
    }  
</style>  
2024-04-26 13:39 负责人:无 分享
已邀请:
爱豆豆

爱豆豆 - 办法总比困难多

是对的啊
文档里也没说有-1啊
取消就是触发的fail
包括你点击遮罩层也是触发的fail
只有你成功点击了选项才回触发success 拿到点击项的索引

  • 1***@qq.com (作者)

    谢谢,主要想确定一下

    2024-04-26 14:22

要回复问题请先登录注册