【发布时间】:2021-11-29 13:06:03
【问题描述】:
我正在使用this npm package 在我的 Vue 应用程序中发送通知。在按照说明操作并在main.ts 上添加所需的用法后,我在尝试使用它的功能时不断得到:
Property '$notify' does not exist on type 'Shop'
main.ts:
import Vue from 'vue'
import Notifications from 'vue-notification'
import App from './App.vue'
Vue.use(Notifications)
new Vue({
render: h => h(App)
}).$mount('#app')
<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import Character from "./Character.vue";
import Vendor from "./Vendor.vue";
@Component<Shop>({
components: {
Character,
Vendor
},
})
export default class Shop extends Vue {
sellItem(itemID) {
this.$notify({
title: 'Important message',
text: 'Hello user!'
});
}
}
</script>
我尝试在 .vue 文件中导入组件,但它无法识别类型。我究竟做错了什么?我找不到任何解决方案...
谢谢。
【问题讨论】:
-
从组件上下文中尝试
Vue.notify -
@apokryfos 我忘了说我也试过用那个来称呼它,但是得到
Property 'notify' does not exist on type 'VueConstructor<Vue>'.Vetur(2339)这个。 -
确保文件
main.ts也被导入或再次执行Vue.use -
@Layan 我无法重现此demo 中的问题。什么工具报告该错误?
标签: javascript typescript vue.js vuejs2