main.js
import { PriceFilter } from './utils/priceFilter.js'
// 遍历文件中的所有方法注册为一个个的过滤器
Object.keys(PriceFilter).forEach(key => {
Vue.filter(key, PriceFilter[key])
})
priceFilter.js
// 分别截取 价格小数点前后的数字
export const PriceFilter = {
// 小数点前
radixPointBefore: price => {
if (price == undefined) {
return
}
price = price.toString()
if (price && price.indexOf(".") != -1) {
return price.substring(0, price.indexOf("."))
} else {
return price;
}
},
// 小数点后
radixPointAfter: price => {
if (price == undefined) {
return
}
price = price.toString()
if (price && price.indexOf(".") != -1) {
return price.substring(price.indexOf("."), price.length)
} else {
return ".00";
}
}
}
vue.js
<view class="current_price">
<span>{{ item.promotion_money | radixPointBefore }}</span>
<span style="font-size: 24rpx">{{ item.promotion_money | radixPointAfter }}</span>
</view>
效果图