我想在 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>
最佳答案
使用 v-html
指示
<template>
<div >
Vue
<span v-html='jsonFunc'></span>
</div>
</template>
<script>
export default {
data() {
return {
a: {
country: "England:↵ - Liverpool↵ - Chelsea↵ - Arsenal↵ - MU↵ - City",
},
testObj: "",
};
},
computed: {
jsonFunc() {
return (this.testObj = this.a.country.replace(/↵/g, "<br/>"));
},
},
};
</script>
关于javascript - 如何在 VueJS 中渲染换行符↵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66926538/