如何解决Cordova + VueJS + Typescript上的“ Navigator”类型上不存在属性“ notification”
App.vue是我的主要布局文件。它具有导航功能和许多其他功能。
<template>
<div
id="app"
role="main"
>
...
<router-view />
...
<script lang="ts">
...
import { Vue,Component } from 'vue-property-decorator'
@Component
export default class App extends Vue {
...
onResume():any {
setTimeout(function() {
navigator.notification.alert("Device has resumed!",null,"Message","OK")
navigator.notification.beep(2)
},0)
}
...
mounted() {
document.addEventListener("resume",this.onResume)
}
...
</script>
配置
在src-cordova/package.json
中,拥有
...
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {},"cordova-plugin-dialogs": {}
},...
**编译时**
When I `npm run cordova-build-browser`
461:19 Property 'notification' does not exist on type 'Navigator'.
459 | onResume():any {
460 | setTimeout(function() {
> 461 | navigator.notification.alert("Device has resumed!","OK")
| ^
462 | navigator.notification.beep(2)
463 |
464 | this.$store.dispatch("upcoming")
我收到类似的哔哔声错误消息
**我已经考虑过**
npm run cordova-serve-browser
运行正常。我仍然需要构建浏览器
我已经尝试过了
Error: Property 'notification' does not exist on type 'Navigator'
但是这里提到了打字文件。而且我知道typings.json
已过时
我尝试过
(navigator as any).notification.alert("Device has resumed!","OK")
(navigator as any).notification.beep(2)
但是我得到
462:9 error Unexpected newline between function and ( of function call no-unexpected-multiline
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。