《鸿蒙开发-答案之书》Toast工具类
项目中肯定用的toast,封装个toast工具类,好用就拿去
示例代码:
export default function showToast(message?: string|Resource, duration: number = 1500) {
if (message == null || typeof message === 'undefined' || (typeof message === 'string' && message.length === 0)){
return
}
try {
promptAction.showToast({
message: message,
duration: duration,
})
} catch (error) {
console.error(`showToast args error code is ${error.code}, message is ${error.message}`);
}
}