<el-table :data="tableData">
<el-table-column label="備註" width="210" align="center">
<template slot-scope="scope">
<span>{{changeRemarkLength(scope.row.remark)}}</span>
</template>
</el-table-column>
</el-table>
<script>
data () {
return {
tableData:[]
}
},
methods: {
},
//計算屬性
computed:{
//改變備註的長度,長度大於14位就用...代替剩餘內容
changeRemarkLength(){
//text就是所傳參數
return function (text) {
if(text.length > 14){
return text.slice(0,14)+"...";
}else{
return text;
}
}
}
}
</script>
說明:
1、計算屬性傳參,方法裏寫成 return function (val) {}形式
2、<template slot-scope="scope"> slot-scope="scope"代表插槽的意思,這裏 scope 代表行 data。scope.row取整行數據