網(wǎng)站首頁 Vue 正文
使用過濾器filters的this為undefined
vue中的過濾器更偏向于對文本數(shù)據(jù)的轉(zhuǎn)化,而不能依賴this上下文,如果需要使用到上下文this我們應(yīng)該使用computed計算屬性的或者一個method方法
vue filter過濾器的用法
{undefined{ args | filterFun }} |是管道符 用法如下
{{ time | formatDate }}
過濾器中
filters: { ? ? ? ? formatDate: value => { ?? ??? ? ? let date = new Date(value) ?? ??? ? ? let y = date.getFullYear() ?? ??? ? ? let MM = date.getMonth() + 1 ?? ??? ? ? MM = MM < 10 ? "0" + MM : MM ?? ??? ? ? let d = date.getDate() ?? ??? ? ? d = d < 10 ? "0" + d : d ?? ??? ? ? let h = date.getHours() ?? ??? ? ? h = h < 10 ? "0" + h : h ?? ??? ? ? let m = date.getMinutes() ?? ??? ? ? m = m < 10 ? "0" + m : m ?? ??? ? ? let s = date.getSeconds() ?? ??? ? ? s = s < 10 ? "0" + s : s ?? ??? ? ? return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s ?? ??? ?} ? ? }
time 相當(dāng)于想要過濾的值 傳遞給formatDate的參數(shù)
也可以多參數(shù) {undefined{ time | formatDate(“嘿哈”) }}
這時過濾器中
//time 傳遞給 value ? ?"嘿哈" 傳遞給 arg1 formatDate: (value,arg1) => { ?? ?...... }
原文鏈接:https://blog.csdn.net/qq_38396070/article/details/107385360
相關(guān)推薦
- 2022-09-22 set數(shù)據(jù)結(jié)構(gòu)/map數(shù)據(jù)結(jié)構(gòu)(ES6)
- 2023-07-18 A component required a bean of type ‘xxx‘ that cou
- 2023-10-17 npm 下載依賴項顯示proxy代理錯誤network ‘proxy‘ config is set
- 2022-10-25 搭建Redis集群遇到的問題:Waiting for the cluster to join~~~
- 2021-12-13 linux系統(tǒng)AutoFs自動掛載服務(wù)安裝配置_Linux
- 2022-08-10 Python實現(xiàn)以主程序的形式執(zhí)行模塊_python
- 2022-12-26 python畫圖時linestyle,color和loc參數(shù)的設(shè)置方式_python
- 2022-04-09 Oracle?19c?RAC?手工建庫的搭建過程_oracle
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支