美文网首页
js short-code-sheet

js short-code-sheet

作者: 泠泉 | 来源:发表于2019-04-01 09:43 被阅读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')
    

    相关文章

      网友评论

          本文标题:js short-code-sheet

          本文链接:https://www.haomeiwen.com/subject/qejmbqtx.html