vue+elementui項目去除html標簽


1、html代碼

     <div slot="ti_content" style="width: 100%;height: 250px;overflow-y: auto;">
        <span v-html="highlight(addFromData.ti_content)"></span>
      </div>

  

       <el-table-column slot="ti_content" label="文章內容" align="left" width="300px">
          <template slot-scope="scope">
            <div class="contentClass">{{scope.row.ti_content.replace(/<[^>]+>/g, '')}}</div>
          </template>
        </el-table-column>

  如果想使用方法的話,可以

        <el-table-column slot="ti_content" label="文章內容" align="left" width="300px">
          <template slot-scope="scope">
            <div class="contentClass">{{ highlight(scope.row.ti_content) }}</div>
          </template>
        </el-table-column>

   方法 methods:[ 適合table之類的不用顯示文字樣式 ]
   highlight (item) {
      return item.replace(/<[^>]+>/g, '')// 去掉所有的html標記
    },

  

 

2、methods:

// 該方法適用於 v-html 的顯示 如下圖
highlight (item) { //const removehtml = (str = '') => str.replace(/<[/!][^<>]>/gi, '') //return removehtml(item)
},

  

 

 

 


免責聲明!

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



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