Home > Web Front-end > JS Tutorial > body text

How to use vue.js to implement price formatting (code attached)

亚连
Release: 2018-05-18 13:50:29
Original
2399 people have browsed it

The following is the vue.js price formatting I compiled for you. Interested students can take a look.

Here is a commonly used price formatting method, which is very practical in e-commerce price processing. We can see the effect

How to use vue.js to implement price formatting (code attached)

Here a filter is used in the price data, and the price is processed by retaining decimal places through this filter.

HTML

<div class="price">
   <span v-html="goods.sale_price|format"></span>
   <span class="price-before">¥{{"这里是价格数据"}}
   </span>
  </div>
Copy after login

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(&#39;.&#39;)[1].substring(1)==0){
value = Number(value).toFixed(1);
}
_val = value.split(&#39;.&#39;);
return html = &#39;¥<span>&#39;+_val[0]+&#39;</span><em>.&#39;+_val[1]+&#39;</em>&#39;;
}
}
Copy after login

The above is the vue.js price formatting I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

JS native code implements two-way data binding (can be used directly, already encapsulated)

Detailed explanation of the use of Js apply() (including code)

About the simple operation of downloading files in js (attached code, detailed answer)

The above is the detailed content of How to use vue.js to implement price formatting (code attached). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template