vue使用 js-pinyin汉字转拼音字母

 

安装

 

npm install js-pinyin --save

使用

<script>
let pinyin = require('js-pinyin');

export default {
 data(){
     return{
         
     }
 },
 mounted(){
    console.log(pinyin.getFullChars('博客'));//BoKe
    console.log(pinyin.getCamelChars('博客'));//BK
    console.log(pinyin.getCamelChars('12博客34'));//12BK34
    console.log(pinyin.getCamelChars('a博客b'));//aBKb
 }
};
</script>

 

    // 只保留字符串拼音大写及数字
    getTitle(title) {
      const py = pinyin.getCamelChars(title)
      return py.replace(/[^0-9a-zA-Z]/g, '').toLocaleUpperCase()
    },

 

参考:https://blog.csdn.net/weixin_44111864/article/details/110928684

posted @ 2021-10-08 18:07  CHUNYIN  阅读(1390)  评论(0)    收藏  举报