device.js
v2.0.0
ไลบรารีปฏิกิริยาเพื่อสังเกตคุณสมบัติเบราว์เซอร์และอุปกรณ์ที่จำเป็น
เวอร์ชัน 2 ไม่เข้ากันได้กับเวอร์ชัน 1 ตรวจสอบการเปลี่ยนแปลงสำหรับรายละเอียดเพิ่มเติม
chrome, safari, firefox, facebook, instagram, edge, ie, opera, phantomjswebp, webrtc, webgl, pwaportrait, landscapedesktop, mobile, tablet, tvandroid, ios, windows, macoswidth, height yarn add @maoosi/device.jsการใช้งานขั้นพื้นฐาน:
รหัสนี้จะบันทึก viewportWidth หลังจากดูพอร์ตทุกตัวปรับขนาดให้เป็น 200 มิลลิวินาที:
import { device , watch } from '@maoosi/device.js'
watch ( async ( ) => {
console . log ( device . viewportWidth )
} ) device เป็นวัตถุพร็อกซี่ปฏิกิริยาที่สามารถสังเกตได้และเปิดเผยคุณสมบัติต่อไปนี้:
interface device {
deviceOS : string | null
deviceType : string | null
deviceOrientation : string | null
browser : string | null
browserVersion : string | null
viewportHeight : number | null
viewportWidth : number | null
isBrowserEvergreen : boolean | null
isPWA : boolean | null
isSupportedWebP : boolean | null
isSupportedWebGL : boolean | null
isSupportedWebRTC : boolean | null
}ใช้ vue.js:
เนื่องจาก device เป็นวัตถุพร็อกซี่ปฏิกิริยา vue.js สามารถสังเกตการเปลี่ยนแปลงได้โดยไม่จำเป็นต้องใช้วิธี watch :
< template >
< pre > {{ deviceInfo }} </ pre >
</ template >
< script >
import { device } from '@maoosi/device.js'
export default {
data ( ) {
return { deviceInfo : device }
}
}
</ script > ก่อนอื่นตรวจสอบให้แน่ใจว่าคุณติดตั้งบริการต้นแบบทันที vue.js: https://cli.vuejs.org/guide/prototyping.html
จากเทอร์มินัลของคุณ:
yarn playgroundยินดีต้อนรับการมีส่วนร่วมปัญหาและคำขอคุณสมบัติ
ลิขสิทธิ์© 2021 Maoosi
โครงการนี้ได้รับใบอนุญาต MIT