Today, when writing vue project, check out the data in the database of wanted to change the display according to the conditions. There is a query data
: Formatter, can achieve this effect, ado, this is my example:
<el-table-column prop="operatetime" label="关联时间" :formatter="timeFormat"></el-table-column>
timeFormat is a method
methods: { timeFormat(row, column) { const date = new Date(row.operatetime); var year = parseInt(date.getFullYear()); if (year > 2018) { return row.operatetime; } else { return ""; } }
Later, the results of which I want to add in some style, I like to write " <span style =" Color: Red "> Time associated </ span>",
the answer was not enough. Being distressed occasion to see this great God wrote the following address:
https://blog.csdn.net/qq_35493664/article/details/83832497
on the perfect solution, Remark about!
as follows:
<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>