vue 計算屬性傳參,並返回處理結果

<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取整行數據

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章