js short-code-sheet

2019-04-01  本文已影响0人  泠泉

add between to Number


created () {
  /* eslint-disable no-extend-native */
  Number.prototype.between = function (a, b) {
    let inclusive = true
    let min = Math.min(a, b)
    let max = Math.max(a, b)
    return inclusive ? this >= min && this <= max : this > min && this < max
  }
},

保留锚点的下划线,又不跳转


href="javascript:void(func)"

禁用浏览器后退


window.addEventListener('popstate', (e) => {
  window.history.forward(1)
  history.pushState(null, null, document.URL)
})

导出Excel


export function download (url, options) {
  let form = $('<form>')
  form.attr('style', 'display:none')
  form.attr('target', '')
  form.attr('method', 'post')
  form.attr('action', url)
  let tokenInput = $('<input>')
  let typeInput = $('<input>')
  tokenInput.attr('type', 'hidden')
  tokenInput.attr('name', 'token')
  tokenInput.attr('value', localStorage.getItem('default_auth_token'))
  typeInput.attr('type', 'hidden')
  typeInput.attr('name', 'options')
  typeInput.attr('value', JSON.stringify(options))
  $('body').append(form)
  form.append(tokenInput)
  form.append(typeInput)
  form.submit()
}

导入懒加载


const UserCenter = () => import('components/user-center/user-center')
上一篇下一篇

猜你喜欢

热点阅读