vue 汉字转首字母

首先安装

npm install js-pinyin --save

 

引入

import pinyin from 'js-pinyin'

 

使用案例

let name = '小明'

let char = ''

pinyin.setOptions({checkPolyphone:false,charCase:0});

char = pinyin.getCamelChars(this.name)

// char = XM

 

github地址:https://github.com/waterchestnut/pinyin

posted @ 2020-11-27 14:52  哎呀哦豁  阅读(1282)  评论(0)    收藏  举报