vue處理換行符


1.處理換行符

<tr class="unread" v-for="(item,index) in DataList" :key="index">
    <td class="salesUnitName">{{item.salesUnitName}}</td>
    <td class="createUserName">{{item.createUserName}}</td>
    <td class="halfContent" v-show="typeListVal == 4" v-html="keepTextStyle(item.domesticOpponentSituation)"></td>
    <td class="halfContent" v-show="typeListVal == 4" v-html="keepTextStyle(item.overseaOpponentSituation)"></td>
    <td class="allContent" v-show="typeListVal == 6" v-html="keepTextStyle(item.financeSituation)"></td>
    <td class="allContent" v-show="typeListVal == 7" v-html="keepTextStyle(item.productDemand)"></td>
    <td class="allContent" v-show="typeListVal == 8" v-html="keepTextStyle(item.marketSituation)"></td>
    <td class="allContent" v-show="typeListVal == 9" v-html="keepTextStyle(item.humanResources)"></td>
    <td class="allContent" v-show="typeListVal == 10" v-html="keepTextStyle(item.projectProgressSituation)"></td>
    <td class="allContent" v-show="typeListVal == 11" v-html="keepTextStyle(item.workMatters)"></td>                                
</tr>
keepTextStyle(val){
  return val.replace(/\n/g,"<br/>")
},

 

直接使用val.replace會報錯,查一下replace用法,就知道stringObject.replace(regexp/substr,replacement),所以stringObject必須是字符串才可以,犯了一個致命的錯誤是接受過來要的后台數據並不是string類型,所以報錯了,改正如下即可(變成字符串)

        keepTextStyle(val){
            console.log(val)
            console.log(typeof val)
            console.log((typeof val)!='undefined')
            return  (val + '').replace(/\n/g,"<br/>")
        },

  

 

 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM