圆月山庄资源网 Design By www.vgjia.com
需求:vue中,除了在模板中使用过滤器,有时候,methods中也需要使用filters中的过滤器,
网友hongz1125提出的解决办法:
this.$options.filters[filter](...args) //这种方法很简单,也很实用
下面是我的方法,有点复杂。建议使用上面网友说的方法。
filters: { formatScore(score) { if (score < 20) { score = '不合格'; } else if (score >= 20 && score <= 27) { score = '合格'; } else if (score >= 28 && score <= 31) { score = '良好'; } else if (score > 31) { score = '优秀'; } return score } }, methods: { formatScore(score) { if (score < 20) { score = '不合格'; } else if (score >= 20 && score <= 27) { score = '合格'; } else if (score >= 28 && score <= 31) { score = '良好'; } else if (score > 31) { score = '优秀'; } return score }, getPhysicalResult() { this.$http.get('/rc_ChildTest/testResult').then((res) => { this.isDisplayIcon = this.formatScore(score参数);//使用过滤器方法,需要单独写一个一模一样的方法。通过this调用 }) }, },
解决方法:
1.建立一个公共的report.js文件,提取封装公共js
export default { formatScore(score) { if (score < 20) { score = '不合格'; } else if (score >= 20 && score <= 27) { score = '合格'; } else if (score >= 28 && score <= 31) { score = '良好'; } else if (score > 31) { score = '优秀'; } return score }, }
2.导入report.js 并使用
import report from 'js文件所在位置'
filters: { formatScore(score) { return report.formatScore(score);//使用导入的report.js中的report.formatScore方法 } }, methods: { getPhysicalResult() { this.$http.get('/rc_ChildTest/testResult').then((res) => { this.isDisplayIcon = report.formatScore(score参数);//这里直接使用导入的report.js中的report.formatScore方法。在methods方法中可以使用过滤器中的方法。 }) }, },
我是这么解决的,大家如果还有更好的方法,希望大家写在评论里,欢迎大家批评指正。
以上这篇在Vue methods中调用filters里的过滤器实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年10月19日
2024年10月19日
- 群星《歌手2024 第4期》[FLAC/分轨][563.76MB]
- RiffKitten-ChaosParade(2024)[24-44,1]FLAC
- RuneKlakegg-Nattevandrer(2024)[24-96]\FLAC
- 赖冰霞.2006-金嗓典藏辑2IN1(南方金点系列)2CD【南方】【WAV+CUE】
- 群星.1988-国语金曲尽精英VOL.2【瑞成】【WAV+CUE】
- 张宇.1999-雨一直下【EMI百代】【WAV+CUE】
- 袁娅维.2021-月亮失眠了(DELUXE)【华纳】【FLAC分轨】
- AlanBroadbent-JazzFunk(2024)[24-44,1]
- 梅艳芳《绝代芳华》开盘母带[低速原抓WAV+CUE]
- ABC唱片-《外国精逊母带直刻神奇黑胶[APE+CUE].
- 群星《天赐的声音第五季 第6期》[320K/MP3][101.43MB]
- 群星《天赐的声音第五季 第6期》[FLAC/分轨][526.16MB]
- 群星《说唱梦工厂 第2期》[320K/MP3][96.37MB]
- 杨宗宪.1994-留你留袂着【有容唱片】【WAV+CUE】
- 李翊君.2005-勇敢的爱【创意唱片】【WAV+CUE】