过滤器(filters),也是一个函数
- 位置,放置filters的位置与el、data、methods等并列;
<script>
const app = new Vue({
el:'#app',
data(){
return {
price: 100.123,
}
},
methods:{
// getShowPrice(price){
// return '¥' + price.toFixed(2)
// }
},
filters:{
showPrice(price){
return '¥' + price.toFixed(2)
}
}
})
</script>
- 使用
<template>
<h1>{{price | showPrice }}</h1>
</template>
- 显示