gpt4 book ai didi

javascript - 如何在 VueJS 中渲染换行符↵?

转载 作者:行者123 更新时间:2023-12-04 07:51:52 25 4
gpt4 key购买 nike

我想在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com