vue3使用计算属性computed代替vue2过滤器filter

1.提取公共方法文件到common.js:

function formatPrice(price) {
	return '¥' + price.toFixed(2);
}

export {
	formatPrice
}

2.引入common.js,并使用计算computed监听动态值

	import { formatPrice } from "@/utils/common"

...
		computed:{
			getPrice(){
				return formatPrice;
			}
		},

3.页面使用计算属性即可

<view class="old-price">{
   
   {getPrice(goods.goods_price)}}</view>

猜你喜欢

转载自blog.csdn.net/qq_34569497/article/details/131083661