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 (将#修改为@)