一、过滤器filter
1.1 局部过滤器 写在vue里
filters: {//过滤器
// 定义局部过滤器
toFixedPrice: function(price) {
let priceStr = price.toFixed(2)
return "¥" + priceStr
}
}
应用
<h2>总价:{
{totalPrice | toFixedPrice}}</h2><!-- 管道符 | -->
<!-- 数据 | 过滤器函数-->
1.2 全局过滤器 写在vue外
// 全局过滤器
Vue.filter('toFixedPrice', function (value) {
if (!value) return ''
value = value.toFixed(2)
return "¥" + value
})
二、v-for列表渲染
v-for遍历数组、对象、字符串、指定次数
<div id="app">
<!-- 遍历数组 -->
<ul>
<li v-for="item in persons" :key="item.id">
{
{item.name}}-{
{item.age}}
</li>
</ul>
&l