将中文转为拼音。不依赖任何三方库,几KB原生实现,有良好的兼容性,不挑运行环境。
ohpm install @nutpi/pinyin
// 引入拼音转换库
import PinyinConverter from '@nutpi/pinyin';
// 创建拼音转换器实例
const converter = new PinyinConverter();
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
aboutToAppear(): void {
this.message = converter.convert("坚果派")
}
build() {
RelativeContainer() {
Text(this.message)
.id('HelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
})
}
.height('100%')
.width('100%')
}
}
image-20241226232652114
https://ohpm.openharmony.cn/#/cn/detail/@nutpi%2Fpinyin
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有