Vue中使用把汉字转化为拼音字母

源码git地址

https://github.com/waterchestnut/pinyin.git

安装

npm install js-pinyin
 
import pinyin from 'js-pinyin'

使用示例

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'));

程序中调用

<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>