vue elment table根據返回值修改樣式


今天在寫vue項目的時候,查詢出的數據庫的數據想根據條件修改顯示。查詢資料有一個 

:formatter,可以實現這個效果,廢話不多說,這個是我的例子:
<el-table-column prop="operatetime" label="關聯時間" :formatter="timeFormat"></el-table-column>

 

timeFormat是一個方法

  methods: {
    timeFormat(row, column) {
      const date = new Date(row.operatetime);
      var year = parseInt(date.getFullYear());
      if (year > 2018) {
        return row.operatetime;
      } else {
        return "";
      }
    }

 



后來,我又想在結果里面加一些樣式,我像這樣寫"<span style="color:red">關聯時間</span>",
答案當時是不行的。正在苦惱之際,看到這個大神寫的,地址如下:
https://blog.csdn.net/qq_35493664/article/details/83832497
就完美解決了,Remark一下!
如下:
  <el-table-column prop="relationemid" label="關聯狀態">
        <template scope="scope">
          <span v-if="scope.row.relationemid===1" style="color: blue">已關聯</span>
          <span v-else>未關聯</span>
        </template>
      </el-table-column>
 
         

 




免責聲明!

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



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