NuxtJS:在 mixin 中匯入元件時出現問題
P粉267791326
P粉267791326 2024-03-31 20:49:22
0
1
320

我的堆疊是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粉267791326
P粉267791326

全部回覆(1)
P粉321676640

我從此連結找到了答案。

我加入了

vue-shims.d.ts

declare module "*.vue" {
  import Vue from 'vue'
  export default Vue
}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!