在需要用到的页面引入外部filter
可以在html页面用管道符来使用{{item.price| moneyFilter}},这样可以很方便地显示金额时保留两位小数。
<div>¥{{item.price | moneyFilter}}</div>
filters:{
moneyFilter(money){
return toMoney(money)
}
},
外部filter
//第一种方法
export function toMoney(money) {
let newMoney=money;
if(newMoney){//判读传过来的值是否为空,不为空时
newMoney=newMoney.toFixed(2)
}else{//为空时
newMoney=0;
newMoney=newMoney.toFixed(2)
}
return newMoney;
}
//第二种方法
export function toMoney(money=0) {
return money.toFixed(2);
}
编程式导航,如何使用name的时候那么传递参数的时候就要用params ,
反之如何使用的是path(path:"/goods")的时候,那么传递参数的时候就要使用query,
接收路由参数的时候,使用params传递接收就要使用params接收,使用query传递接收就使用query接收
this.$router:
this.$router.push({name:'Goods',params:{goodsId:id}})//跳转到指定页面
//当使用params传递参数的时候,接收参数也用params接收,如下:
this.$route.params.goodsId
//当使用query传递参数的时候,接收参数也用query接收,如下:
this.$router.push({name:'Goods',query:{goodsId:this.goodsId}})//传递
this.$route.query.goodsId//接收
this.$router.go(-1);//后退
this.$route:
表示可以获取当前路由路径的参数