自定义nuxt.js组件目录的正确配置是什么?

<h1>Hello people</h1>

我正在学习使用nuxt.js,我的问题是关于自定义目录的使用,该目录不同于使用nuxt.js制作的应用程序的默认结构

The issue: index.vue can't load .vue components from my components custom dir

在nuxt.config.file中,我有这个配置文件:

  /*
  **Custom directory structure configuration paths
  **Change as desires
  **Important Note: This is a function not well documented on nuxt.org
  */

  dir: {
    views: 'views',components: 'views/components',layouts: 'views/layouts',pages: 'views/pages',controllers: 'controllers/',middleware: 'controllers/middleware',models: 'models',data: 'models/data',files: 'models/files',store: 'models/store',sources: 'sources',assets: 'sources/assets',static: 'sources/static'
  },

,并在nuxt的index.vue默认文件中创建项目com,并将其放在文件末尾

<script>
import Logo from '~components/Logo.vue'
import VuetifyLogo from '~components/VuetifyLogo.vue'

export default {
  components: {
    Logo,VuetifyLogo
  }
}
</script>

和其他数据一样,jsconfig.json文件的默认内容为

{
  "compilerOptions": {
    "baseUrl": ".","paths": {
      "~/*": ["./*"],"@/*": ["./*"],"~~/*": ["./*"],"@@/*": ["./*"]
    }
  },"exclude": ["node_modules",".nuxt","dist"]
}

shell或命令提示符中的错误消息是

ERROR  Failed to compile with 2 errors                friendly-errors 12:12:09

These dependencies were not found:                    friendly-errors 12:12:09
                                                      friendly-errors 12:12:09
* ~/components/Logo.vue in 
  ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib
  ??vue-loader-options!./views/pages/index.vue?vue&type=script&lang=js&
* ~/components/VuetifyLogo.vue in 
  ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib
  ??vue-loader-options!./views/pages/index.vue?vue&type=script&lang=js&

                                                      friendly-errors 12:12:09

To install them,you can run: npm install --save ~/components/Logo.vue ~/components/VuetifyLogo.vue

在localhost / 3000处的错误消息是

Module not found: Error: Can't resolve 
'~/components/Logo.vue' 
in '/home/user/desktop/nuxt/views/pages'

Module not found: Error: Can't resolve 
'~/components/VuetifyLogo.vue' 
in '/home/user/desktop/nuxt/views/pages'

如果我已经将“ views / components /”和“ views”中的组件定义为“ views”,我不知道为什么要在“ views / pages /”上寻找组件,有关我所做工作的更多信息,请参见:

https://forum.vuejs.org/t/anyone-know-how-to-rename-move-a-nuxt-folder/44876/2

使用默认目录结构时没有错误。

节日快乐

quzhuanglin 回答:自定义nuxt.js组件目录的正确配置是什么?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2870926.html

大家都在问