uni-app 定义 全局过滤器(filter)、“Tue Mar 08 2022 14:44:42 GMT+0800 (中国标准时间)“ 过滤为 “2022-03-08“ 格式
普通filter
<view class="date">{{date | formatDate}}
</view>
filters: {formatDate(date) {const nDate = new Date(date)const nyear = nDate.getFullYear()const nmonth = (nDate.getMonth()+1).toString().padStart(2,0)const nday = nDate.getDate().toString().padStart(2,0)return nyear+'-'+nmonth+'-'+nday}
},
全局过滤器(filter)
//和 普通filter 的用法相同<view class="date">{{date | formatDate}}
</view>
//以下代码写在 main.js 中Vue.filter("formatDate", (date) => {const nDate = new Date(date)const nyear = nDate.getFullYear()const nmonth = (nDate.getMonth()+1).toString().padStart(2,0)const nday = nDate.getDate().toString().padStart(2,0)return nyear+'-'+nmonth+'-'+nday
})
效果图:
main.js
import App from './App'
import Vue from 'vue'Vue.filter("formatDate", (date) => {const nDate = new Date(date)const nyear = nDate.getFullYear()const nmonth = (nDate.getMonth()+1).toString().padStart(2,0)const nday = nDate.getDate().toString().padStart(2,0)return nyear+'-'+nmonth+'-'+nday
})Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({...App
})
app.$mount()
uni-app 定义 全局过滤器(filter)、“Tue Mar 08 2022 14:44:42 GMT+0800 (中国标准时间)“ 过滤为 “2022-03-08“ 格式相关推荐
- Tue Jun 28 2022 15:30:29 GMT+0800 (中国标准时间) 日期格式化
1. Tue Jun 28 2022 15:30:29 GMT+0800 (中国标准时间) 转换为 2022-06-28 15:30:29 代码如下 const d = new Date(Tue Ju ...
- Tue Nov 24 2020 00:00:00 GMT 0800 (中国标准时间)变成yyyy-MM-dd格式
element中日期选择器获取各式为yyyy-MM-dd <el-col :span="11"><el-date-picker type="date&q ...
- Tue Sep 03 2019 00:00:00 GMT+0800 (中国标准时间)怎么变成时间戳
问题说明 js收到数据var a="Tue Sep 03 2019 00:00:00 GMT+0800 (中国标准时间),Sun Oct 06 2019 00:00:00 GMT+0800 ...
- 亲测:如何将Sat Mar 14 2020 00:00:00 GMT+0800 (中国标准时间)转换成正常格式yy-MM-dd。字符串日期的比较compareTo方法。
public static void main(final String[] args) { final SimpleDateFormat sdFormat=new SimpleDateFormat( ...
- vue指令02---自动获取焦点(全局自定义指令Vue.directive())和全局过滤器Vue.filter() 的学习...
1.1 自动获取焦点 在自动获取焦点的学习中涉及到了一个钩子函数 mounted(),它表示页面一加载进来就执行函数里面的内容,(和window.onload相似,这样有助于理解),mounted 钩 ...
- Vue过滤器(filter)
过滤器函数,必须被定义到 filter 节点之下 过滤器本质上是函数 语法: <div id="app"> <p>{{message | capi}} ...
- vue私有过滤器和全局过滤器
1.私有过滤器 在filters 节点下定义的过滤器,称为"私有过滤器",因为它只能在当前vm 实例所控制的el 区域内使用. <!DOCTYPE html> < ...
- Gateway网关-全局过滤器
全局过滤器 上一节学习的过滤器,网关提供了31种,但每一种过滤器的作用都是固定的.如果我们希望拦截请求,做自己的业务逻辑则没办法实现. 全局过滤器作用 全局过滤器的作用也是处理一切进入网关的请求和微服 ...
- Vue中的过滤器(filter)
一.Vue中的过滤器是什么 过滤器(filter)是输送介质管道上不可缺少的一种装置,大白话,就是把一些不必要的东西过滤掉,过滤器实质不改变原始数据,只是对数据进行加工处理后返回过滤后的数据再进行调用 ...
最新文章
- centos 学习日记 文件默认权限:umaks
- linux启动自动挂载共享文件,linux中自动挂载windows 共享目录
- VTK:可视化之MultipleViewports
- 【转】如何缩进你的代码?
- 在windows xp下编译出ffmpeg.exe
- Django补充知识点——用户管理
- 招商银行网站在chrome中 布局出现大问题,如图
- 如何在Linux中查看所有正在运行的进程 1
- 当10年BI数据总监遇到烂需求、烂数据时,他做了这几件事
- Spring Security(5):自定义决策
- logback log4j log4j2 性能实测
- CryoSat-2卫星介绍
- 在 Web 浏览器中运行(PowerApps)应用
- 信号计算机联锁试题,计算机联锁试题.doc
- 小明历险记:规则引擎Drools教程详解
- 安卓项目图片缓存实现
- 修改UA在PC中访问只能在微信中打开的链接
- 三、nginx服务的nginx.conf的参数配置解析
- 先学java还是c_先学C语言还是Java
- BloomFilter布隆过滤器