首先想到用正则进行replace;
后来想到了一个更简单的方法:
template
<el-table-column v-for="(col, index) in columns" :key="index" :prop="col.prop" :label="col.label">
<template slot-scope="{row}">
<span :style="convertSpace(row[col.key])">
{{ removeSpace(row[col.key]) }}
</span>
</template>
</el-table-column>
methods
convertSpace (text) {
let count = 0
if (text && text.includes(' ')) {
count = [text.split(' ').length - 1]
}
return { paddingLeft: count * 0.5 + 'em' }
},
removeSpace (text) {
let str = ''
if (text && text.includes(' ')) {
str = text.split(' ').join('')
} else {
str = text
}
return str
},
网友评论