收录一个常用的函数

const inBrowser = typeof window !== 'undefined'

function supportWebp () {
  if (!inBrowser) return false

  let support = true
  const d = document

  try {
    let el = d.createElement('object')
    el.type = 'image/webp'
    el.style.visibility = 'hidden'
    el.innerHTML = '!'
    d.body.appendChild(el)
    support = !el.offsetWidth
    d.body.removeChild(el)
  } catch (err) {
    support = false
  }

  return support
}

dailyvuejs
1.6k 声望307 粉丝

目前专注 Vue CLI 3 源码和 vue.config.js 配置内部设计等学习分享