1. テキストをフォーマットするためのカスタムフィルタ
2.定義
export default {
data() {
return {
money = 5.2100
}
},
filters: {
// 小数点以下2桁を保持するための切片
twoDecimal (value) {
// 現在のデータを小数点以下3桁までインターセプトする。
let tempVal = parseFloat(value).toFixed(3)
let realVal = tempVal.substring(0, tempVal.length - 1)
return realVal
}
}
}
3.使用法:2つの場所で使用できます。
{{ money | twoDecimal }}
{{ テキスト文字列| フィルター関数}}
<div v-bind:id="money | twoDecimal"></div>
4.併用
{{ money | twoDecimal | フィルター1 | フィルター2}}
{{ テキスト文字列| フィルター関数1| フィルター関数2| フィルター関数 3}}