vue字符串切割


一、概述

現有一個基於element-ui開發的后台頁面,效果如下:

 

 

需要將公司名進行切割,每一行,顯示一個公司。

 

二、代碼實現

test.vue

<template>
  <el-table
    :data="tableData"
    border
    style="width: 362px">
    <el-table-column
      prop="id"
      label="id"
      width="180">
    </el-table-column>
    <el-table-column
      prop="name"
      label="公司名"
      width="180">
      <template slot-scope="scope">
        <div v-for="item in companyCut(scope.row.name)">
          {{item}}<br>
        </div>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
  export default {
    name: "test",
    data() {
      return {
        tableData: [{
          id: '2016-05-02',
          name: '阿里雲',
        }, {
          id: '2016-05-04',
          name: '騰訊控股、字節跳動',
        }, {
          id: '2016-05-01',
          name: '美團、金蝶國際、台積電',
        }]
      }
    },
    methods: {
      // 切割公司列表
      companyCut(name){
        let company=name.split("")
        return company
      },
    }
  }
</script>

<style scoped>

</style>

 

效果如下:

 


免責聲明!

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



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