The use of formatter of ElementUI

to format the content Function(row, column, cellValue)
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Morris.js Charts</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="../plugins/elementUI/elementUI.css">
  <style>
   
  </style>
</head>

<body class="">
   
<div id="demo">
 <el-table
    :data="tableData3"
    style="width: 100%"
    height="250">
    <el-table-column
      fixed
      prop="date"
      label="日期"
      width="150"
      :formatter="formatDate" 
      >
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名">
      
    </el-table-column>
    <el-table-column
      prop="province"
      label="省份">
      
    </el-table-column>
    <el-table-column
      prop="city"
      label="市区">
      
    </el-table-column>
    <el-table-column
      prop="address"
      label="地址">
     
    </el-table-column>
    <el-table-column
      prop="zip"
      label="邮编">
     
    </el-table-column>
  </el-table>
</div>
 <script src="../js/vue.js"></script>
 <script src="../plugins/elementUI/elementUI.js"></script>
  <script>
  var demo = new Vue({
    el: '#demo',
    data: {
       tableData3: [{
          date: '2016-05-03',
          name: '王小虎',
          province: '上海',
          city: '普陀区',
          address: '上海市普陀区金沙江路 1518 弄',
          zip: 200333
        }, {
          date: '2016-05-02',
          name: '王小虎',
          province: '上海',
          city: '普陀区',
          address: '上海市普陀区金沙江路 1518 弄',
          zip: 200333
        }, {
          date: '2016-05-04',
          name: '王小虎',
          province: '上海',
          city: '普陀区',
          address: '上海市普陀区金沙江路 1518 弄',
          zip: 200333
        }, {
          date: '2016-05-01',
          name: '王小虎',
          province: '上海',
          city: '普陀区',
          address: '上海市普陀区金沙江路 1518 弄',
          zip: 200333
        }, {
          date: '2016-05-08',
          name: '王小虎',
          province: '上海',
          city: '普陀区',
          address: '上海市普陀区金沙江路 1518 弄',
          zip: 200333
        }, {
          date: '2016-05-06',
          name: '王小虎',
          province: '上海',
          city: '普陀区',
          address: '上海市普陀区金沙江路 1518 弄',
          zip: 200333
        }, {
          date: '',
          name: '王小虎',
          province: '上海',
          city: '普陀区',
          address: '上海市普陀区金沙江路 1518 弄',
          zip: 200333
        }]
    },
    methods: {
       formatDate(row, column, cellValue){
          //return row.date == "2016-05-04" ? '男' : row.sex == 0 ? '女' : '未知';
          //格式化是针对表格内容即使data数据
           var newDate = row.date== "" ? "-" : row.date.replace(/-/g,"/")
           return newDate
       }
  }
  })
  </script>
</body>

</html>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324594785&siteId=291194637