首页 > 解决方案 > 组件未安装在 nuxt.js 中

问题描述

我创建新文件 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

为什么呢?

标签: gitnpmvue.jsnuxt.js

解决方案


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

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

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


推荐阅读