Skip to content

Commit f1281b8

Browse files
committed
Don't use v-html for default formatter
The string value should not be parsed as HTML. At least when using default formatter. Resolves #71
1 parent 23faf93 commit f1281b8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/components/simple-text.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<template>
22
<div>
33
<slot></slot>
4-
<span :class="`vjs-value vjs-value__${dataType}`" v-html="textFormatter(data)"/>
4+
<span v-if="customValueFormatter" :class="valueClass" v-html="customFormatter(data)"/>
5+
<span v-else :class="valueClass">{{ defaultFormatter(data) }}</span>
56
</div>
67
</template>
78

@@ -18,6 +19,10 @@
1819
customValueFormatter: Function
1920
},
2021
computed: {
22+
valueClass () {
23+
return `vjs-value vjs-value__${this.dataType}`
24+
},
25+
2126
// 当前数据类型
2227
dataType () {
2328
return getDataType(this.data)
@@ -36,14 +41,10 @@
3641
return text
3742
},
3843
39-
textFormatter (data) {
40-
if (this.customValueFormatter) {
41-
return this.customValueFormatter(
42-
data, this.currentKey, this.parentData
43-
) || this.defaultFormatter(data)
44-
} else {
45-
return this.defaultFormatter(data)
46-
}
44+
customFormatter (data) {
45+
return this.customValueFormatter(
46+
data, this.currentKey, this.parentData
47+
) || this.defaultFormatter(data)
4748
}
4849
}
4950
}

0 commit comments

Comments
 (0)