[英]Quasar cordova-plugin-device - error 'device' is not defined
我創建了一個新的類星體項目,添加了cordova並進行了一些嘗試。
一切正常,我可以在手機上部署應用程序並在模擬器中運行它。
現在,我需要獲取一些設備信息,我想為此使用cordova-plugin-device。 插件正在加載,就像我安裝的每個插件一樣。 我可以在 iOS xCode 模擬器的開發者窗口 (safari) 中看到它。
現在,我嘗試獲取設備信息,如文檔中所述:
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device/index.html
App.vue 中的類似內容:
mounted: function () {
document.addEventListener('deviceready', this.onDeviceReady, false)
},
methods: {
onDeviceReady: function () {
console.log('cordova', cordova)
console.log('device', device)
}
...
但是控制台總是出現以下錯誤:
錯誤“設備”未定義 no-undef
我該如何解決? 我已經刪除了平台並重新添加了它。
我沒有想法,無法在互聯網上找到任何相關內容。
提前致謝 干杯巴斯蒂
在類星體社區的幫助下,我已經可以解決我的問題。
神奇的詞是: window.device
。
嘗試這個
var Type = (navigator.userAgent.match(/iPad/i)) == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "null";
alert(Type);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.