【发布时间】:2021-06-29 18:02:32
【问题描述】:
我想在 Vue 中有 ↵ 时渲染一个换行符。
我关注了How can I use v-html on the vue?,但我无法关注。
我尝试过的:
var app = new Vue({
el: '#app',
data() {
return {
a: {
country: "England:↵ - Liverpool↵ - Chelsea↵ - Arsenal↵ - MU↵ - City",
},
testObj: "",
};
},
computed: {
jsonFunc() {
return (this.testObj = this.a.country.replace(/↵/g, "<br/>"));
},
},
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div>
Vue
{{ jsonFunc }}
</div>
</div>
【问题讨论】:
-
<div v-html="jsonFunc"></div>codesandbox
标签: javascript vue.js