安装
npm install js-pinyin
import pinyin from 'js-pinyin'
element-ui 中使用示例
<el-form-item label="姓名" prop="name" :rules="[{required: true, message:'姓名不能为空', trigger:'blur'}]">
<el-input v-model="inputForm.name" placeholder="请填写姓名" maxlength="100" @input="inputName"></el-input>
</el-form-item>
import Pinyin from 'js-pinyin'
components: {
Pinyin
}
data() {
return {
inputForm: {
name: '',
namePin: ''
}
}
}
inputName(e) {
this.inputForm.namePin = Pinyin.getFullChars(e)
}
官方地址: https://www.npmjs.com/package/js-pinyin