【问题标题】:NuxtJS : problem import ing Component in mixinNuxtJS:在 mixin 中导入组件的问题
【发布时间】:2022-01-08 03:29:39
【问题描述】:

我的堆栈是 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)

【问题讨论】:

  • 如果你在这里写AppAlert.ts会发生什么?因为我假设如果你不写扩展,它默认为.js
  • AppAlert 是一个组件,它的扩展名是 .vue ,我添加了 .vue 但它没有修复
  • 也许可以尝试检查this onethis one

标签: typescript vue.js nuxt.js vue-property-decorator


【解决方案1】:

我从this link找到了答案。

我加了

vue-shims.d.ts

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    • 2017-05-25
    相关资源
    最近更新 更多