怎么在Vue中使用filters过滤器?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

html
{{message | filters2| filters3(true,priceCount)}}
js
var app = new Vue({
el: "#app",
data: {
message: 199,
priceCount:.8
},
filters:{
filters2:function (arg) {
console.log("arg:"+arg)
if(arg>100){
return arg-8;
}else {
return arg;
}
},
filters3:function (arg_1,arg_2,arg_3) {
var result;
console.log("arg_1:"+arg_1)
console.log("arg_2:"+arg_2)
console.log("arg_3:"+arg_3)
if(arg_2){
result = arg_1*arg_3;
console.log("result"+result);
return result;
}else{
result =arg_1;
console.log("result"+result);
return result
}
}
}
});控制台日志
helloVue.js:17 arg:199
helloVue.js:26 arg_1:191
helloVue.js:27 arg_2:true
helloVue.js:28 arg_3:0.8
helloVue.js:35 result152.8
先来看看两个过滤器的入参
第一个过滤器filters2的入参是199,是Vue实例中绑定的message
第二个过滤器filters3的入参是191、(第一个过滤器返回的值)false(第二个过滤器的第一个入参)、0.8(第二个过滤器的第二个入参)
1、Vue实例中的message是199
2、第一个过滤器,大于100的数减8(理解为满100减8),199-8=191传给第二个过滤器作为第一个参数
3、第二个过滤器,有两个入参,第一个是boolean值(理解为是否打折),第二个是0.8(折扣)。
看完上述内容,你们掌握怎么在Vue中使用filters过滤器的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联网站建设公司行业资讯频道,感谢各位的阅读!
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
本文标题:怎么在Vue中使用filters过滤器-创新互联
转载源于:http://www.scyingshan.cn/article/gphho.html


咨询
建站咨询
