js监听刷新事件 颜色16进制转rgb 阻止页面滚动 关闭vue-cli的eslint

beforeunload:在当页面卸载(关闭)或刷新时调用

这次用到 在跳转到其他路由 使用历史返回时 本地缓存不删除 但刷新要删除 达到刷新随机选项内容 返回保留操作内容目的

//清除本地缓存ztl
 clearZtl() {
            window.sessionStorage.removeItem("ztl")
 }
window.addEventListener("beforeunload",this.clearZtl)

颜色 十六进制转rgb

export function transferColorToRgb(color) {
  if (typeof color !== 'string' && !(color instanceof String)) return console.error("请输入16进制字符串形式的颜色值");
  color = color.charAt(0) === '#' ? color.substring(1) : color;
  if (color.length !== 6 && color.length !== 3) return console.error("请输入正确的颜色值")
  if (color.length === 3) {
    color = color.replace(/(\w)(\w)(\w)/, '$1$1$2$2$3$3')
  }
  let reg = /\w{2}/g;
  let colors = color.match(reg);
  for (let i = 0; i < colors.length; i++) {
    colors[i] = parseInt(colors[i], 16).toString();
  }
  return 'rgb(' + colors.join() + ')';
};

阻止页面滚动 在生成海报时用户页面滚动 会导致错位

//禁止滚动
                document.addEventListener("touchmove",this.disabledScroll,{ passive: false })

//禁止滚动
        disabledScroll(e) {
            e.preventDefault()
        }

关闭vue-cli的eslint
创建vue.config.js

module.exports = {
    lintOnSave: false
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值