简体   繁体   English

如何创建一个方法来替换换行符的分号?

[英]How to create a method that replace semicolons for line breaks?

I want to create a method that receives a string, replaces the semicolons (";") with line breaks, and then returns it.我想创建一个方法来接收一个字符串,用换行符替换分号(“;”),然后返回它。

I tried it with that's code:我用那段代码试过了:

methods: {
    programasMethod(programas){
       if(programas){
        return programas.replaceAll(";", "\n");
       }  
    }
}

I tried using the method programasMethod(programas) inside a template but it returns the string without the semicolons (";") and without the lines breaks.我尝试在模板中使用方法programasMethod(programas)但它返回没有分号(“;”)且没有换行符的字符串。

<div class="col-lg-8">
    <template v-for="item of actividades">
        <ul>
            <li>{{ programasMethod(item.programa) }}</li>
        <ul>
    </template>
</div>

该图像显示了网络上的结果

Could you help me?你可以帮帮我吗?

Try this:试试这个:

<div class="col-lg-8">
    <template v-for="item of actividades">
         <ul v-if="item.programa">
            <li v-for="(elem, i) in item.programa.split(';')" :key="i">{{ elem }} <br /></li>
        </ul>
    </template>
</div>

[EDIT] [编辑]

You can also do this:您也可以这样做:

<div class="col-lg-8">
    <template v-for="item of actividades">
        <ul>
            <li v-html="programasMethod(item.programa)"></li>
        <ul>
    </template>
</div>

and

methods: {
    programasMethod(programas){
       if(programas){
        return programas.replaceAll(";", "<br />");
       }  
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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