组件对参数做处理并返回,判断参数是否为数字,如果是数字则带上元,如果没有则不带。
<template>
<div>
{{ newMoney }}
</div>
</template>
<script>
export default {
name: 'type',
components: {},
props: {
money: {
type: String | Number,
default () {
return 0
}
}
},
computed: {
newMoney: function() {
var name = ''
if (/^\d+$/.test(this.money)) {
name = this.money + "元"
} else {
name = this.money
}
return name
}
},
data() {
return {}
}
}
</script>
<style lang="scss" scoped>
</style>