常用函数封装1:复制文本信息
<el-button type="primary" @click="copyLink">复制链接</el-button>
copyLink () {
const transfer = document.createElement('input')
document.body.appendChild(transfer)
transfer.value = '已复制链接'
transfer.select()
if (document.execCommand('copy')) {
document.execCommand('copy')
}
document.body.removeChild(transfer)
this.$message.success('已复制手机号')
}
常用函数封装2:判断苹果设备
isApple() {
return navigator.userAgent.indexOf('Mac') > -1 || navigator.userAgent.indexOf('Ios') > -1
}
常用函数封装3:判断微信浏览器(做兼容)
isWx() {
const ua = window.navigator.userAgent.toLowerCase()
const iswx = ua.match(/MicroMessenger/i) == 'micromessenger'
return iswx
},
isPcWx() {
const platform = navigator.platform
const isMobile = platform.indexOf('Win') === -1 && platform.indexOf('Mac') === -1
const ua = window.navigator.userAgent.toLowerCase()
const isQw = ua.match(/WxWork/i) == 'wxwork'
return !isMobile && !isQw && this.isWx
}