{{ }} 里面可以是:
- 表達式
- 字符串
- 函數
- 正則表達式
- boolean
主要有
1.{{num + 1}} 運算符
data:{ num:5 }
2.{{status ? ‘succeed’ : ‘failed’}} 三元表達式
data:{ status: true }
3.{{changeTime()}} 運行函數
changeTime(){ return this.value.replace(/\d/g,'') }
可以拿到時間戳之后,用new Date轉換成時間對象,然后進入changeTime這個自己定義的函數里
<el-table-column slot="ti_content" label="文章內容" align="left" width="300px">
<template slot-scope="scope">
<div class="contentClass">{{ highlight(scope.row.ti_content) }}</div>
</template>
</el-table-column>
// 方法 methods:[ 適合table之類的不用顯示文字樣式 ]
highlight (item) {
return item.replace(/<[^>]+>/g, '')// 去掉所有的html標記
},
4.{{}} 可以寫正則表達式
<div id="app"> <p>{{value.replace(/,/g,'')}}</p> //把全部的逗號去掉 </div> <script> new Vue({ el: '#app', data:{ value: '3,800,239.00' } }) </script>