<template>
<view>
<button @click="callPhone('1234567891')">拨打电话</button>
</view>
</template>
export default {
methods: {
callPhone(phoneNumber) {
// 判断手机号是否为空
if (phoneNumber) {
// 调用拨打电话的API
uni.makePhoneCall({
phoneNumber: phoneNumber, // 电话号码
success: function () {
console.log('拨打电话成功');
},
fail: function () {
console.log('拨打电话失败');
}
});
} else {
uni.showToast({
title: '电话号码不能为空',
icon: 'none'
});
}
}
}
}