首页 > 其他分享 >直播软件搭建,全局过滤器(时间,年月日,一千加逗号处理)

直播软件搭建,全局过滤器(时间,年月日,一千加逗号处理)

时间:2023-05-03 14:22:05浏览次数:48  
标签:逗号 date let time 过滤器 年月日

直播软件搭建,全局过滤器(时间,年月日,一千加逗号处理)

步骤一:处理数据 

export const formatYmd = (date) => {
  let time = new Date(date)
 
  let y = time.getFullYear()
  let m = time.getMonth() + 1
  let d = time.getDate()
 
  return [y, m, d].map((v) => String(v).padStart(2, '0')).join('/')
}
 
//处理年月日时分秒
export const formatYmdHms = (date) => {
  let time = new Date(date)
 
  let y = time.getFullYear()
  let M = time.getMonth() + 1
  let d = time.getDate()
 
  let h = time.getHours()
  let m = time.getMinutes()
  let s = time.getSeconds()
 
  return (
    [y, M, d].map((v) => String(v).padStart(2, '0')).join('-') +
    ' ' +
    [h, m, s].map((v) => String(v).padStart(2, '0')).join(':')
  )
}
 
//处理时分秒
export const formatHms = (date) => {
  let time = new Date(date)
 
  let h = time.getHours()
  let m = time.getMinutes()
  let s = time.getSeconds()
 
  return [h, m, s].map((v) => String(v).padStart(2, '0')).join(':')
}
 
//一千加逗号
export const formatNum = (num) => {
  let reg = /\d{1,3}(?=(\d{3})+$)/g
  // 表示前面有1~3个数字,后面的至少由一组3个数字结尾
 
  return (num + '').replace(reg, '$&,')

​步骤二:main.js 注册全局过滤器

//引入过滤器函数
import * as filters from '@/filters'
 
//循环注册 全局过滤器
Object.keys(filters).forEach((key) => {
  //参数1 过滤器名称 参数2 过滤器函数体
  Vue.filter(key, filters[key])
})

 以上就是 直播软件搭建,全局过滤器(时间,年月日,一千加逗号处理),更多内容欢迎关注之后的文章

 

标签:逗号,date,let,time,过滤器,年月日
From: https://www.cnblogs.com/yunbaomengnan/p/17369013.html

相关文章

  • SpringSecurity过滤器之UsernamePasswordAuthenticationFilter
    UsernamePasswordAuthenticationFilter处理表单登录及认证。AbstractAuthenticationProcessingFilter#doFilterprivatevoiddoFilter(HttpServletRequestrequest,HttpServletResponseresponse,FilterChainchain) throwsIOException,ServletException{ if(!requires......
  • SpringSecurity过滤器之LogoutFilter
    LogoutFilter用于注销登录。privatevoiddoFilter(HttpServletRequestrequest,HttpServletResponseresponse,FilterChainchain) throwsIOException,ServletException{ if(requiresLogout(request,response)){ Authenticationauth=SecurityContextHolder.getC......
  • SpringSecurity过滤器之DefaultLoginPageGeneratingFilter
    DefaultLoginPageGeneratingFilter用于生成默认登录页。privatevoiddoFilter(HttpServletRequestrequest,HttpServletResponseresponse,FilterChainchain) throwsIOException,ServletException{ booleanloginError=isErrorPage(request); booleanlogoutSuccess......
  • SpringSecurity过滤器之SecurityContextHolderAwareRequestFilter,RequestCacheAwareFi
    SecurityContextHolderAwareRequestFilterSecurityContextHolderAwareRequestFilter对Servelet3.0的api做了封装。publicvoiddoFilter(ServletRequestreq,ServletResponseres,FilterChainchain) throwsIOException,ServletException{ chain.doFilter(this.requestF......
  • 哈希表与布隆过滤器
    一、哈希的整体思想最简单的哈希表其实就是数组,从数组中取出一个数的时间复杂度是O(1)的。但是数组下标类型是整型的,万一我的下标类型不是整型了该怎么办呢?比如说字符串型,典型的就是我想查找某个单词存不存在。还有些更复杂的数据类型,比如自定义的类型。那么问题就来了,如何满足任......
  • springSecurity过滤器之AnonymousAuthenticationFilter
    SpringSecurity提供了匿名登录功能,让我们不登录也能访问。比如/anoy路径及子路径都能匿名访问,配置如下:@ConfigurationpublicclassMySecurityConfigextendsWebSecurityConfigurerAdapter{@Overrideprotectedvoidconfigure(HttpSecurityhttp)throwsException......
  • SpringSecurity过滤器之SecurityContextPersistenceFilter
    SecurityContextPersistenceFilter在请求之前从配置的SecurityContextRepository获得的信息填充SecurityContextHolder,并在请求完成并清除上下文holder后将其存储回存储库。默认情况下,它使用HttpSessionSecurityContextRepository。privatevoiddoFilter(HttpServletRequestreq......
  • SpringSecurity过滤器之SessionManagementFilter
    SessionManagementFilter检测用户自请求开始以来是否已通过身份验证,如果已通过,则调用SessionAuthenticationStrategy以执行任何与会话相关的活动,例如激活会话固定保护机制或检查多个并发登录。配置如下:@ConfigurationpublicclassMySecurityConfigextendsWebSecurityConfigur......
  • mysql中列转行,并多个字段转到一行中的一个字段上,中间用逗号分开
    mysql中列转行,并多个字段转到一行中的一个字段上,中间用逗号分开 SELECT group_concat(a.idSEPARATOR',')ASidsFROM ( SELECT * FROM tablename WHERE 1=1 ORDERBY rand() LIMIT10 )a ......
  • 接口过期过滤器
    注解类importjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;/***过期接口通知*/@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.METHOD,......