简体   繁体   中英

How to render line-break ↵ in VueJS?

I want to render a line break whenever there's a ↵ in Vue.

I followed How can I use v-html on the vue? but I am unable to follow.

What I have tried:

 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>

Use v-html directive

 <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM