Vue3 uses computed attribute computed instead of vue2 filter filter

1. Extract the public method file to common.js:

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

export {
	formatPrice
}

2. Introduce common.js and use computed to monitor dynamic values

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

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

3. The page can use computed properties

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

Guess you like

Origin blog.csdn.net/qq_34569497/article/details/131083661