可以使用setInterval函数和@ohos.vibrator (振动)联合实现无限振动的功能。参考demo:import vibrator from '@ohos.vibrator'; import { BusinessError } from '@ohos.base'; import List from '@ohos.util.List'; @Entry @Component struct Index13 { @State message: string = 'Hello World'; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold).onClick(()=>{ try { setInterval(() => { vibrator.startVibration({ type: 'time', duration: 1000, }, { id: 0, usage: 'alarm' }, (error: BusinessError) => { if (error) { console.error(`Failed to start vibration. Code: ${error.code}, message: ${error.message}`); return; } console.info('Succeed in starting vibration'); }); }, 1000); } catch (err) { let e: BusinessError = err as BusinessError; console.error(`An unexpected error occurred. Code: ${e.code}, message: ${e.message}`); } }) } .width('100%') } .height('100%') } }参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-timer-0000001813576724https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-vibrator-0000001774122078\#ZH-CN\_TOPIC\_0000001811316862\_\_vibratorstartvibration9可以使用setInterval函数和@ohos.vibrator (振动)联合实现无限振动的功能,使用vibrator得先在配置文件中配置ohos.permission.VIBRATE权限。
可以使用setInterval函数和@ohos.vibrator (振动)联合实现无限振动的功能。
参考demo:
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-timer-0000001813576724
https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-vibrator-0000001774122078\#ZH-CN\_TOPIC\_0000001811316862\_\_vibratorstartvibration9
可以使用setInterval函数和@ohos.vibrator (振动)联合实现无限振动的功能,使用vibrator得先在配置文件中配置ohos.permission.VIBRATE权限。