首页  >  问答  >  正文

NuxtJS:在 mixin 中导入组件时出现问题

我的堆栈是NuxtjsNuxt-property-decorator

我做了一个 mixin 以避免重复方法

该方法需要一个组件(警报组件)

所以,我在 mixin 中导入了该组件

但是我导入组件时出错

注意:我确信导入地址是真实的

mixin/logOut.ts 从 'vue' 导入 Vue

import { Component } from 'nuxt-property-decorator'
import AppAlert from '~/components/Common/AppAlert'
@Component
export class LogOut extends Vue {
  async LogOut() {
    const confirm = await this.$dialog.show({
      component: AppAlert,
      props: {
        title: { text: 'Exit ?', icon: 'exclamation-thick' },
        body: 'Exit Connector ?',
        btn: { text: 'Confirm', icon: 'power', color: 'error' }
      }
    })
    
    if (confirm) {
      this.$auth.logout()
    }
  }
}

错误文本是:

Cannot find module '~/components/Common/AppAlert' or its corresponding type declarations.ts(2307)

P粉267791326P粉267791326182 天前325

全部回复(1)我来回复

  • P粉321676640

    P粉3216766402024-04-01 17:53:44

    我从此链接找到了答案。

    我添加了

    vue-shims.d.ts

    declare module "*.vue" {
      import Vue from 'vue'
      export default Vue
    }

    回复
    0
  • 取消回复