首页 > 解决方案 > VUE Js Cordova,navigator.device 未定义

问题描述

我正在尝试在 VueJs Cli 3 中使用 cordova-plugin-media-capture 来实现音频录制,这意味着当我面对 navigator.device 时未定义。其他功能,如 navigator.vibration 和 navigator.camera 工作正常。尝试了所有解决方法不同的论坛仍然没有运气,欢迎您的宝贵意见

在 index.html 中包含了 cordova.js 并安装了设备插件,仍然没有用。

Main.ts

Vue.config.productionTip = false
const init = () => {
new Vue({
 router,
 store,
 vuetify,
 render: h => h(App)
}).$mount('#app')
}

declare let navigator : any;
declare let device : any;
document.addEventListener("deviceready", () => {
 init();
 console.log(navigator.device);
 console.log("Ready, Render the App");
});


// If we are not in Cordova, manually trigger the deviceready event
const isCordovaApp = false;
if (!isCordovaApp){
 document.dispatchEvent(new CustomEvent("deviceready", {}));
}

科尔多瓦配置.xml

 <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <plugin name="cordova-plugin-device" spec="^2.0.3" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">

标签: androidcordovavue.jscordova-pluginsvue-cli-3

解决方案


推荐阅读