Vue-過濾器

過濾器

時間戳格式化

實現方式

  • 計算屬性
  • 方法
  • 過濾器

基礎依賴

  • day.min.js 下載鏈接
  • 放到 相對路徑 js 目錄下

Computed

  • 代碼
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>過濾器</title><!--  引入Vue  --><script type="text/javascript" src="../js/vue.js"></script><script type="text/javascript" src="../js/dayjs.min.js"></script><style>.base {padding: 5px;height: 100px;}</style></head><body><div id="root"><h1>過濾器-格式化時間</h1><div><h2>當前時間戳:{{curTime}}</h2><!-- 計算屬性 --><h3>計算屬性:{{fmtTime}}</h3></div></div></body><script type="text/javascript">Vue.config.productionTip = false; // 阻止vue在啟動是生成生產提示const vm = new Vue({el: "#root",data: {name: "Vue 扛把子",// curTime: new Date().getTime(),curTime: 1748675500506,},computed: {fmtTime(){console.log(" computed format time ...")return dayjs(this.curTime).format('YYYY-MM-DD HH:mm:ss')}},methods: {},});</script>
</html>
  • 效果

在這里插入圖片描述

Methods

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>過濾器</title><!--  引入Vue  --><script type="text/javascript" src="../js/vue.js"></script><script type="text/javascript" src="../js/dayjs.min.js"></script><style>.base {padding: 5px;height: 100px;}</style></head><body><div id="root"><h1>過濾器-格式化時間</h1><div><h2>當前時間戳:{{curTime}}</h2><!-- 計算屬性 --><h3>計算屬性:{{fmtTime}}</h3><!-- Methods方法 --><h3>Methods方法:{{formatTime()}}</h3></div></div></body><script type="text/javascript">Vue.config.productionTip = false; // 阻止vue在啟動是生成生產提示const vm = new Vue({el: "#root",data: {name: "Vue 扛把子",// curTime: new Date().getTime(),curTime: 1748675500506,},computed: {fmtTime(){console.log(" computed format time ...")return dayjs(this.curTime).format('YYYY-MM-DD HH:mm:ss')}},methods: {formatTime(){console.log(" methods format time ...")return dayjs(this.curTime).format('YYYY-MM-DD HH:mm:ss')}},});</script>
</html>
  • 效果

在這里插入圖片描述

Filters

無參過濾器
  • 代碼
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>過濾器</title><!--  引入Vue  --><script type="text/javascript" src="../js/vue.js"></script><script type="text/javascript" src="../js/dayjs.min.js"></script><style>.base {padding: 5px;height: 100px;}</style></head><body><div id="root"><h1>過濾器-格式化時間</h1><div><h2>當前時間戳:{{curTime}}</h2><!-- 計算屬性 --><h3>計算屬性:{{fmtTime}}</h3><!-- Methods方法 --><h3>Methods方法:{{formatTime()}}</h3><!-- 過濾器 --><h3>無參過濾器:{{curTime | timeFormater}}</h3></div></div></body><script type="text/javascript">Vue.config.productionTip = false; // 阻止vue在啟動是生成生產提示const vm = new Vue({el: "#root",data: {name: "Vue 扛把子",// curTime: new Date().getTime(),curTime: 1748675500506,},computed: {fmtTime(){console.log(" computed format time ...")return dayjs(this.curTime).format('YYYY-MM-DD HH:mm:ss')}},methods: {formatTime(){console.log(" methods format time ...")return dayjs(this.curTime).format('YYYY-MM-DD HH:mm:ss')}},filters: {timeFormater(value){console.log(" No args filters format time ...")return dayjs(value).format('YYYY-MM-DD HH:mm:ss')}}});</script>
</html>
  • 效果

在這里插入圖片描述

有參過濾器
  • 代碼
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>過濾器</title><!--  引入Vue  --><script type="text/javascript" src="../js/vue.js"></script><script type="text/javascript" src="../js/dayjs.min.js"></script><style>.base {padding: 5px;height: 100px;}</style></head><body><div id="root"><h1>過濾器-格式化時間</h1><div><h2>當前時間戳:{{curTime}}</h2><!-- 計算屬性 --><h3>計算屬性:{{fmtTime}}</h3><!-- Methods方法 --><h3>Methods方法:{{formatTime()}}</h3><!-- 過濾器 --><h3>無參過濾器:{{curTime | timeFormater}}</h3><h3>有參過濾器:{{curTime | timeFormater('YYYY年MM月DD日 HH時mm分ss秒')}}</h3></div></div></body><script type="text/javascript">Vue.config.productionTip = false; // 阻止vue在啟動是生成生產提示const vm = new Vue({el: "#root",data: {name: "Vue 扛把子",// curTime: new Date().getTime(),curTime: 1748675500506,},computed: {fmtTime(){console.log(" computed format time ...")return dayjs(this.curTime).format('YYYY-MM-DD HH:mm:ss')}},methods: {formatTime(){console.log(" methods format time ...")return dayjs(this.curTime).format('YYYY-MM-DD HH:mm:ss')}},filters: {timeFormater(value,formatStr='YYYY-MM-DD HH:mm:ss'){console.log(" filters format time ... :" + formatStr)return dayjs(value).format(formatStr)}}});</script>
</html>
  • 效果

在這里插入圖片描述

鏈式過濾器
  • 代碼
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>過濾器</title><!--  引入Vue  --><script type="text/javascript" src="../js/vue.js"></script><script type="text/javascript" src="../js/dayjs.min.js"></script><style>.base {padding: 5px;height: 100px;}</style></head><body><div id="root"><h1>過濾器-格式化時間</h1><div><h2>當前時間戳:{{curTime}}</h2><!-- 計算屬性 --><h3>計算屬性:{{fmtTime}}</h3><!-- Methods方法 --><h3>Methods方法:{{formatTime()}}</h3><!-- 過濾器 --><h3>無參過濾器:{{curTime | timeFormater}}</h3><h3>有參過濾器:{{curTime | timeFormater('YYYY年MM月DD日 HH時mm分ss秒')}}</h3><h3>鏈式過濾器:{{curTime | timeFormater('YYYY年MM月DD日 HH時mm分ss秒') | spliceStr}}</h3></div></div></body><script type="text/javascript">Vue.config.productionTip = false; // 阻止vue在啟動是生成生產提示const vm = new Vue({el: "#root",data: {name: "Vue 扛把子",// curTime: new Date().getTime(),curTime: 1748675500506,},computed: {fmtTime(){console.log(" computed format time ...")return dayjs(this.curTime).format('YYYY-MM-DD HH:mm:ss')}},methods: {formatTime(){console.log(" methods format time ...")return dayjs(this.curTime).format('YYYY-MM-DD HH:mm:ss')}},filters: {timeFormater(value,formatStr='YYYY-MM-DD HH:mm:ss'){console.log(" filters format time ... :" + formatStr)return dayjs(value).format(formatStr)},spliceStr(value){console.log(" filters splice time (年月日)... ")return value.split(" ")[0]}}});</script>
</html>
  • 效果
    在這里插入圖片描述
全局過濾器

格式: Vue.filter(‘filterName’,function(value){})
注意:全局過濾器聲明必須在Vue實例化之前

  • 代碼
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><title>過濾器</title><!--  引入Vue  --><script type="text/javascript" src="../js/vue.js"></script><script type="text/javascript" src="../js/dayjs.min.js"></script><style>.base {padding: 5px;height: 100px;}</style></head><body><div id="root"><h1>過濾器-格式化時間</h1><div><h2>當前時間戳:{{curTime}}</h2><!-- 計算屬性 --><h3>計算屬性:{{fmtTime}}</h3><!-- Methods方法 --><h3>Methods方法:{{formatTime()}}</h3><!-- 過濾器 --><h3>無參過濾器:{{curTime | timeFormater}}</h3><h3>有參過濾器:{{curTime | timeFormater('YYYY年MM月DD日 HH時mm分ss秒')}}</h3><h3>鏈式過濾器:{{curTime | timeFormater('YYYY年MM月DD日 HH時mm分ss秒') |spliceStr}}</h3><h3>全局過濾器:{{curTime | timeFormater | globalStr}}</h3></div></div></body><script type="text/javascript">Vue.config.productionTip = false; // 阻止vue在啟動是生成生產提示Vue.filter("globalStr", function (value) {console.log(" global filter splice time (時分秒)... ");return value.split(" ")[1];});const vm = new Vue({el: "#root",data: {name: "Vue 扛把子",// curTime: new Date().getTime(),curTime: 1748675500506,},computed: {fmtTime() {console.log(" computed format time ...");return dayjs(this.curTime).format("YYYY-MM-DD HH:mm:ss");},},methods: {formatTime() {console.log(" methods format time ...");return dayjs(this.curTime).format("YYYY-MM-DD HH:mm:ss");},},filters: {timeFormater(value, formatStr = "YYYY-MM-DD HH:mm:ss") {console.log(" filters format time ... :" + formatStr);return dayjs(value).format(formatStr);},spliceStr(value) {console.log(" filters splice time (年月日)... ");return value.split(" ")[0];},},});</script>
</html>
  • 效果

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/85186.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/85186.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/85186.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Linux 下 C 語言實現工廠模式

Linux 下 C 語言實現工廠模式&#xff1a;設計理念與實戰 &#x1f9e0; 一、工廠模式簡介什么是工廠模式&#xff1f;C 語言實現設計模式的挑戰 &#x1f3d7;? 二、實現簡單工廠模式&#xff08;Simple Factory&#xff09;1. 定義傳感器接口&#xff08;device.h&#xff0…

用 Appuploader,讓 iOS 上架流程真正“可交接、可記錄、可復用”:我們是這樣實現的

你可能聽說過這樣一類人&#xff1a;上線必找他&#xff0c;證書只有他有&#xff0c;Transporter 密碼在他電腦上&#xff0c;描述文件什么時候過期&#xff0c;只有他知道。 如果你團隊里有這樣一位“發布大師”&#xff0c;他可能是個英雄——但也是個單點風險源。 我們團…

工控機安裝lubuntu系統

工控機安裝lubuntu系統指南手冊 1. 準備 1個8G左右的U盤 下載Rufus&#xff1a; Index of /downloads 下載lubuntu系統鏡像&#xff1a; NJU Mirror Downloads – Lubuntu 下載Ventoy工具&#xff1a; Releases ventoy/Ventoy GitHub 下載后&#xff0c;解壓&#…

MAC上怎么進入隱藏目錄

在Mac上&#xff0c;由于系統保護的原因&#xff0c;一些系統目錄如/usr默認是隱藏的&#xff0c;但可以通過以下方法進入&#xff1a; 方法一&#xff1a;使用Finder的“前往文件夾”功能 打開Finder。使用快捷鍵Command Shift G&#xff0c;或者在菜單欄中選擇“前往”-“…

流媒體基礎解析:視頻清晰度的關鍵因素

在視頻處理的過程中&#xff0c;編碼解碼及碼率是影響視頻清晰度的關鍵因素。今天&#xff0c;我們將深入探討這些概念&#xff0c;并解析它們如何共同作用于視頻質量。 編碼解碼概述 編碼&#xff0c;簡單來說&#xff0c;就是壓縮。視頻編碼的目的是將原始視頻數據壓縮成較…

tomcat服務器以及接受請求參數的方式

1.javaee&#xff1a;意為java企業版&#xff0c;指java企業級開發的規范總和&#xff0c;包含13項技術規范 2.事實上服務器和客戶端進行交互的過程中&#xff0c;有一個前端控制器在中間運作&#xff0c;這個控制器為DispatcherServlet&#xff0c;它負責將客戶端請求的信息包…

武警智能兵器室系統架構設計與關鍵技術解析

在現代化武警部隊建設中&#xff0c;武器彈藥的安全管理與快速響應能力直接影響部隊戰斗力。本文基于某實戰化智能兵器室建設案例&#xff0c;深入解析其系統架構設計、關鍵技術實現及創新管理機制&#xff0c;為安防領域提供可借鑒的解決方案。 整體拓撲結構 系統采用分層分布…

RLHF獎勵模型的訓練

由于 RLHF 的訓練過程中需要依賴大量的人類偏好數據進行學習&#xff0c;因此很難在訓練過程中要求人類標注者實時提供偏好反饋。為此&#xff0c;我們需要訓練一個模型來替代人類在 RLHF 訓練過程中實時提供反饋&#xff0c;這個模型被稱為獎勵模型 &#x1f538;一、 目標函…

reverse_ssh 建立反向 SSH 連接指南 混淆AV [好東西喲]

目錄 &#x1f310; 工具簡介 ?? 前提條件 攻擊主機 (Linux) 目標主機 (Windows) &#x1f4cb; 詳細步驟 步驟 1&#xff1a;安裝 Go 環境 步驟 2&#xff1a;安裝必要依賴 步驟 3&#xff1a;下載并編譯 reverse_ssh 步驟 4&#xff1a;配置密鑰 步驟 5&#xff…

Ubuntu 下搭建ESP32 ESP-IDF開發環境,并在windows下用VSCode通過SSH登錄Ubuntu開發ESP32應用

Ubuntu 下搭建ESP32 ESP-IDF開發環境&#xff0c;網上操作指南很多&#xff0c;本來一直也沒有想過要寫這么一篇文章。因為我其實不太習慣在linux下開發應用&#xff0c;平時更習慣windows的軟件操作&#xff0c;只是因為windows下開發ESP32的應用編譯時太慢&#xff0c;讓人受…

Rust使用Cargo構建項目

文章目錄 你好&#xff0c;Cargo&#xff01;驗證Cargo安裝使用Cargo創建項目新建項目配置文件解析默認代碼結構 Cargo工作流常用命令速查表詳細使用說明1. 編譯項目2. 運行程序3.快速檢查4. 發布版本構建 Cargo的設計哲學約定優于配置工程化優勢 開發建議1. 新項目初始化?2. …

免費且好用的PDF水印添加工具

軟件介紹 琥珀掃描.zip下載鏈接&#xff1a;https://pan.quark.cn/s/3a8f432b29aa 今天要給大家推薦一款超實用的PDF添加水印工具&#xff0c;它能夠滿足用戶給PDF文件添加水印的需求&#xff0c;而且完全免費。 這款PDF添加水印的軟件有著簡潔的界面&#xff0c;操作簡便&a…

NW969NW978美光閃存顆粒NW980NW984

NW969NW978美光閃存顆粒NW980NW984 技術解析&#xff1a;NW969、NW978、NW980與NW984的架構創新 美光&#xff08;Micron&#xff09;的閃存顆粒系列&#xff0c;尤其是NW969、NW978、NW980和NW984&#xff0c;代表了存儲技術的前沿突破。這些產品均采用第九代3D TLC&#xf…

Mysql常用知識3:Kafka和數據庫優化

文章目錄 一、分布式消息系統&#xff08;Kafka相關問題5-10&#xff09;5. Kafka如何保證消息不丟失&#xff1f;6. 項目中Kafka具體怎么使用的&#xff1f;7. 消息異常未發送成功怎么解決&#xff1f;8. 重試具體怎么做的&#xff0c;循環嗎&#xff1f;9. 重試多次失敗怎么辦…

常見的RAG文檔解析輔助工具匯總及企業選型思考

以下當前比較知名的RAG的文檔解析輔助工具的開源項目匯總&#xff0c;包含核心功能、License信息及GitHub地址&#xff1a; 1. RAGFlow 核心功能&#xff1a;支持PDF/掃描件/CAD等23種格式解析&#xff0c;OCR準確率98%&#xff0c;知識圖譜融合&#xff0c;混合檢索&#xf…

基于Sqoop的MySQL-Hive全量/增量同步解決方案(支持多表批量處理

一、全量同步方案設計 1.1 基礎命令模板 sqoop import \ --connect jdbc:mysql://mysql_host:3306/db_name \ --username user \ --password pass \ --table source_table \ --hive-import \ --hive-table target_table \ --hive-overwrite \ # 覆蓋已有表 --num-mappers 8 …

前端學習(7)—— HTML + CSS實現博客系統頁面

目錄 一&#xff0c;效果展示 二&#xff0c;實現博客列表頁 2.1 實現導航欄 2.2 實現個人信息 2.3 實現博客列表 三&#xff0c;實現博客正文頁 3.2 復用 3.4 實現博客正文 四&#xff0c;實現博客登錄頁 4.1 版心 4.2 登錄框 五&#xff0c;實現博客編輯頁 5.1 …

【技能拾遺】——家庭寬帶單線復用布線與配置(移動2025版)

&#x1f4d6; 前言&#xff1a;在家庭網絡拓撲中&#xff0c;客廳到弱電箱只預埋了一根網線&#xff0c;由于已將廣電的有線電視取消并改用IPTV。現在需要解決在客廳布置路由器和觀看IPTV問題&#xff0c;這里就用到單線復用技術。 目錄 &#x1f552; 1. 拓撲規劃&#x1f55…

VTK|實現類似CloundCompare的測量功能

文章目錄 CloundCompare在點、線、面三種模式下的顯示內容? 圖1&#xff1a;點模式? 圖2&#xff1a;線模式? 圖3&#xff1a;面模式 增加控制菜單欄實現測量功能類如何調用項目git鏈接 CloundCompare在點、線、面三種模式下的顯示內容 點 線 面 三張圖展示了 CloudComp…

4000萬日訂單背后,餓了么再掀即時零售的“效率革命”

當即時零售轉向價值深耕&#xff0c;贏面就是綜合實力的強弱。 文&#xff5c;郭夢儀 編&#xff5c;王一粟 在硝煙彌漫的外賣行業“三國殺”中&#xff0c;餓了么與淘寶閃購的日訂單量竟然突破了4000萬單。 而距淘寶閃購正式上線&#xff0c;還不到一個月。 在大額福利優惠…