【问题标题】:component not install in nuxt.js组件未安装在 nuxt.js 中
【发布时间】:2018-11-12 13:32:21
【问题描述】:

我创建新文件 testcomp.vue

在 pages/index.vue 我添加了

import testcomp from 'components/testcomp'

导出默认{}我添加

components:{
    'testcomp': testcomp,
},

之后我运行 npm install --save components/testcomp

在控制台日志中我看到下一个

npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\cmd\git.EXE ls-remote -h -t ssh://git@github.com/components/testcomp.git
npm ERR!
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Nil\AppData\Roaming\npm-cache\_logs\2018-06-02T17_38_50_009Z-debug.log

为什么?

【问题讨论】:

    标签: git npm vue.js nuxt.js


    【解决方案1】:

    您收到错误是因为您将新创建的组件视为一个 npm 包。

    npm install --save package/name 只有在你想安装一个新的远程包时才需要。不适用于在您的计算机上创建的内容。

    另外,如果您使用默认的下一个设置。我认为您的导入与文件结构不匹配。我认为您需要从 '../components/testcomp' 导入 testcomp

    【讨论】:

      【解决方案2】:
      <script>
      import testcomp from '~/components/testcomp'
      
      export default {
          components: {
              testcomp
          }
      }
      </script>
      

      【讨论】:

      • 虽然此代码可能会回答问题,但提供有关 如何 和/或 为什么 解决问题的附加 context 将改善答案的长度长期价值。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人!请edit您的答案添加解释,并说明适用的限制和假设。提及为什么这个答案比其他答案更合适也没有什么坏处。
      猜你喜欢
      • 2020-04-19
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 2015-10-16
      • 2019-11-08
      • 2021-09-25
      • 2015-07-07
      相关资源
      最近更新 更多