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>