根据汉字获取拼音
npm地址
https://www.npmjs.com/package/getpinyin
安装
npm install getpinyin --save
引用
import { getFirstPY, getFullPY } from 'getpinyin'
const { getFirstPY, getFullPY } = require('getpinyin')
使用
console.log(getFirstPY('国')) // g
console.log(getFirstPY('中国')) // zg
console.log(getFullPY('国')) // guo
console.log(getFullPY('中国')) // zhongguo
注意
没有对多音字进行处理