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


免責聲明!

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



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