欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

工作中遇到的一些问题及解决方法(vue)

程序员文章站 2022-06-04 14:34:31
...

1.到账时间:到账时间执行T+1至T+3政策,遇周末顺延

isFriday () {
      let nowDay = new Date()
      let whichWeekday = nowDay.getDay()
      switch (whichWeekday) {
        case 0:
        case 1:
          this.todayAccount = nowDay.getTime() + 24 * 60 * 60 * 1000
          this.toAccount = nowDay.getTime() + 24 * 60 * 60 * 1000 * 3
          break
        case 2:
          this.todayAccount = nowDay.getTime() + 24 * 60 * 60 * 1000
          this.toAccount = nowDay.getTime() + 24 * 60 * 60 * 1000 * 5
          break
        case 3:
          this.todayAccount = nowDay.getTime() + 24 * 60 * 60 * 1000
          this.toAccount = nowDay.getTime() + 24 * 60 * 60 * 1000 * 4
          break
        case 4:
          this.todayAccount = nowDay.getTime() + 24 * 60 * 60 * 1000 * 1
          this.toAccount = nowDay.getTime() + 24 * 60 * 60 * 1000 * 5
          break
        case 5:
          this.todayAccount = nowDay.getTime() + 24 * 60 * 60 * 1000 * 3
          this.toAccount = nowDay.getTime() + 24 * 60 * 60 * 1000 * 5
          break
        case 6:
          this.todayAccount = nowDay.getTime() + 24 * 60 * 60 * 1000
          this.toAccount = nowDay.getTime() + 24 * 60 * 60 * 1000 * 4
          break
      }
    }

在created中调用isFriday()函数,生命周期,vue实例被生成后调用函数

2.开户银行(20字以内显示全名,超出20字,显示前8后8中间使用省略号用“......”连接)

<span>{{hashName | ellipsis}}</span>
filters: {
		    ellipsis (value) {
		      
		      if (!value) return ''
		      if (value.length > 10) {
		      	let all=value.length;
		      	 alert(all)
		      	 let ceshi = all-8
				let hou = str.substring(ceshi,all);
				let fisrt = str.substring(0,8);
				if (all > 20) {
				$(".jianjie").text(fisrt+"…"+hou);
				}
		        //return value.slice(0,20) + '...'
		      }
		      return value
		    }
		  }

3.路由导航守卫(用于后台管理系统登录前的一个判断,跳转路由验证用户登录状态)

router,beforeEach((to,from,next) =>{})

router.beforeEach((to, from, next) => {
  // console.log(to.path)
  if (to.path !== '/login' && to.path !== '/regist') {
    if (localStorage.getItem('sessionId')) {
      next()
    } else {
      next({path: '/login'})
    }
  } else {
    next()
  }
})

to为向后走的路由对象,包括路由的完整信息(router即将进入的路由对象)

from为从哪跳来的路由对象(当前导航即将离开的路由)

next()控制路由向下走,重新定义路由跳转的路由next(‘路由路径) (进行管道中的一个钩子,如果执行完了,则导航的状态就是 confirmed (确认的);否则为false,终止导航。)