1.超小屏幕(手机) 768px以下
2.小屏设备(平板) 768px-992px
3.中等屏幕(旧式电脑) 992px-1200px
4.大屏设备(现代电脑) 1200px以上
TypeScript
<script setup name="welcome">
import { onMounted, ref } from 'vue'
const screenWidth = ref(document.documentElement.clientWidth)
const isPhone = ref(screenWidth.value < 993) // 小于993视为平板及手机
onMounted(() => {
window.addEventListener('resize', () => {
screenWidth.value = document.body.offsetWidth
isPhone.value = document.body.offsetWidth < 993 // 小于993视为平板及手机
})
const nextHandle = () => {
window.location.href = isPhone.value ? 'https://www.baidu.com/' : 'https://element-plus.gitee.io/zh-CN/component/'
}
</script>