VUE 将阿里伯数字转换为中文表示,一般用作排名使用。
<script>export default {data(){return{textArr:[{name:0,value:'十'},{name:1,value:'一'},{name:2,value:'二'},...
·
<script>
export default {
data(){
return{
textArr:[
{name:0,value:'十'},
{name:1,value:'一'},
{name:2,value:'二'},
{name:3,value:'三'},
{name:4,value:'四'},
{name:5,value:'五'},
{name:6,value:'六'},
{name:7,value:'七'},
{name:8,value:'八'},
{name:9,value:'九'}
]
}
},
mounted(){
let text = this.numText(123465);
console.log(text);
},
methods:{
//数字转中文
numText(num){
var numArr = num.toString().split('');
var that = this;
var result = [];
numArr.forEach(res=>{
that.textArr.forEach(item=>{
if(item.name==res){ result.push(item.value) }
})
})
return result.join('');
},
}
}
更多推荐
已为社区贡献4条内容
所有评论(0)