search

Home  >  Q&A  >  body text

NuxtJS: Problem importing components in mixin

My stack is Nuxtjs and Nuxt-property-decorator

I made a mixin to avoid duplicating methods

This method requires a component (alert component)

So, I imported the component in the mixin

ButI got an error when importing the component

Note: I am sure the import address is real

mixin/logOut.ts from 'vue' import 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()
    }
  }
}

The error text is:

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

P粉267791326P粉267791326268 days ago458

reply all(1)I'll reply

  • P粉321676640

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

    I found the answer from this link.

    I added

    vue-shims.d.ts

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

    reply
    0
  • Cancelreply