vue.js实现价格格式化的方法
作者:马优晨 时间:2024-05-10 14:20:06
这里分享一个常用的价格格式化的一个方法,在电商的价格处理中非常的实用,我们可以看一个效果
这里在价格数据的地方使用了一个过滤器,通过这个过滤器对价格做了保留小数位的处理。
HTML
<div class="price">
<span v-html="goods.sale_price|format"></span>
<span class="price-before">¥{{"这里是价格数据"}}</span>
</div>
JS
filters:{ //数据过滤器
format:function(value){
var html,_val;
value =Number(value).toFixed(2);
if(value==0){
value=0;
return html = "¥<span>0</span>";
}else if(value.split('.')[1].substring(1)==0){
value = Number(value).toFixed(1);
}
_val = value.split('.');
return html = '¥<span>'+_val[0]+'</span><em>.'+_val[1]+'</em>';
}
}
以上所述是小编给大家介绍的vue.js实现价格格式化的方法网站的支持!
来源:http://blog.csdn.net/qq_24147051/article/details/71182616
标签:vue,价格,格式化
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
在Typescript中如何使用for...in详解
2023-08-18 15:39:32
mysql压缩包版zip安装配置方法
2024-01-17 08:06:01
![](https://img.aspxhome.com/file/2023/0/72440_0s.jpg)
Python 格式化输出_String Formatting_控制小数点位数的实例详解
2023-11-29 12:09:14
英文罚抄引发的艺术创意
2008-05-13 12:02:00
![](https://img.aspxhome.com/file/UploadPic/20085/13/200851312656339s.jpg)
Django如何创作一个简单的最小程序
2022-09-04 04:57:28
JavaScript简单实现的仿微博留言功能示例
2024-04-17 10:01:33
![](https://img.aspxhome.com/file/2023/5/136425_0s.png)
解析mysql数据库还原错误:(mysql Error Code: 1005 errno 121)
2024-01-15 00:13:13
js链表操作(实例讲解)
2024-04-17 10:37:33
Python后台开发Django会话控制的实现
2022-11-09 22:29:16
浅谈Selenium 控制浏览器的常用方法
2022-03-30 04:40:33
MySQL的性能调优工具:比mysqlreport更方便的tuning-primer.sh
2008-12-08 08:37:00
浅谈Mysql tinyint(1)与tinyint(4)的区别
2024-01-14 10:10:39
Python实现动态图解析、合成与倒放
2022-09-22 12:53:23
![](https://img.aspxhome.com/file/2023/3/133843_0s.gif)
简洁的是最好的吗?
2010-06-24 21:46:00
![](https://img.aspxhome.com/file/UploadPic/20106/24/simple-banner-61s.jpg)
javascript实现依次输入input自动定焦
2024-04-28 10:19:12
![](https://img.aspxhome.com/file/2023/2/132692_0s.png)
机器学习的框架偏向于Python的13个原因
2023-09-28 06:24:42
![](https://img.aspxhome.com/file/2023/8/112008_0s.jpg)
python操作小程序云数据库实现简单的增删改查功能
2024-01-20 08:53:46
![](https://img.aspxhome.com/file/2023/8/97628_0s.jpg)
python简单分割文件的方法
2021-08-09 10:32:33
Go gRPC服务客户端流式RPC教程
2023-07-16 06:08:55
Http头 Range、Content-Range
2010-06-25 19:19:00