js实现汉字转成拼音
原文地址:Vue中使用把汉字转化为拼音字母_卑微小韩的博客-CSDN博客_vue汉字转拼音
源码git地址
https://github.com/waterchestnut/pinyin.git
安装
npm install js-pinyin
import pinyin from 'js-pinyin'
- 1
- 2
- 3
使用示例
import pinyin from 'js-pinyin'
pinyin.setOptions({checkPolyphone: false, charCase: 0});
console.log(pinyin.getFullChars('管理员'));
console.log(pinyin.getCamelChars('管理员'));
console.log(pinyin.getCamelChars('1234'));
console.log(pinyin.getCamelChars('english'));
- 1
- 2
- 3
- 4
- 5
- 6
- 7
程序中调用
<el-form-item label="名称" prop="Name">
<el-input v-model="form.Name" placeholder="名称" size="small" id="Name" @input="createpy()"/>
</el-form-item>
<script>
methods: {
createpy(){
let pinyin = require('js-pinyin')
pinyin.setOptions({checkPolyphone: false, charCase: 0})
this.form.NamePy=pinyin.getCamelChars(this.form.Name)
}
}
</script>