android - 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">
解决方案
推荐阅读
- testing - 推出后 A/B 测试功能
- python - 在 python 中使用 sendevent 使用 adb 进行复杂的滑动?
- c - 使用c中的函数猜数字
- c - (已解决)我在使用 dbg-gdb 包在 Atom 文本编辑器上调试 C 程序时遇到问题。调试器不会在断点处停止
- api - GraphQL 查询中的空手道变量
- r - 我在 " }"'' 中收到错误 'Error: unexpected '}' 。我的括号放错地方了?
- ios - 从 SwiftUI VideoPlayer 的顶部和底部删除黑色空间
- visual-studio-code - 带有占位符转换和制表位的 VS 代码片段
- amazon-web-services - AWS IAM 组和组织单位有什么区别?
- java - 如何到达第一个线程 0 Java?