uniapp中实现<text>文本内容点击可复制或拨打电话

template 部分

vue 复制代码
<template>
    <view>
        <text @tap="handlePhoneClick('1234567890')">1234567890</text>
    </view>
</template>

script 部分

vue 复制代码
export default {
    methods: {
        handlePhoneClick(phoneNumber) {
            uni.showActionSheet({
                itemList: ['复制', '拨打'],
                success: (res) => {
                    if (res.tapIndex === 0) {
                        // 复制操作
                        uni.setClipboardData({
                            data: phoneNumber,
                            success: () => {
                                uni.showToast({
                                    title: '复制成功',
                                    icon: 'success'
                                });
                            },
                            fail: () => {
                                uni.showToast({
                                    title: '复制失败',
                                    icon: 'none'
                                });
                            }
                        });
                    } else if (res.tapIndex === 1) {
                        // 拨打操作
                        uni.makePhoneCall({
                            phoneNumber: phoneNumber
                        });
                    }
                }
            });
        }
    }
};

在上述代码中,当点击包含电话的 标签时,会弹出一个操作菜单,用户可以选择复制电话号码或者直接拨打该号码。uni.setClipboardData用于实现复制功能,uni.makePhoneCall用于实现拨打电话功能。

相关推荐
XMYX-025 分钟前
Spring Boot + Prometheus 实现应用监控(基于 Actuator 和 Micrometer)
spring boot·后端·prometheus
打小就很皮...28 分钟前
HBuilder 发行Android(apk包)全流程指南
前端·javascript·微信小程序
集成显卡1 小时前
PlayWright | 初识微软出品的 WEB 应用自动化测试框架
前端·chrome·测试工具·microsoft·自动化·edge浏览器
@yanyu6662 小时前
springboot实现查询学生
java·spring boot·后端
前端小趴菜052 小时前
React - 组件通信
前端·react.js·前端框架
Amy_cx3 小时前
在表单输入框按回车页面刷新的问题
前端·elementui
酷爱码3 小时前
Spring Boot项目中JSON解析库的深度解析与应用实践
spring boot·后端·json
dancing9993 小时前
cocos3.X的oops框架oops-plugin-excel-to-json改进兼容多表单导出功能
前端·javascript·typescript·游戏程序
AI小智3 小时前
Google刀刃向内,开源“深度研究Agent”:Gemini 2.5 + LangGraph 打造搜索终结者!
后端
后海 0_o3 小时前
2025前端微服务 - 无界 的实战应用
前端·微服务·架构