找不到这种依赖关系 - mevn stack

时间:2018-05-04 21:18:04

标签: node.js mongodb express vue.js

我正在尝试与 nodejs / mongoDB Vue.js 组合。

在线我找到了这个教程: https://medium.com/@anaida07/mevn-stack-application-part-1-3a27b61dcae0

我深入了解教程,我的nodejs服务器正在运行,我的vue.js也在运行。

现在,当我尝试包含postservice时,我得到一个很大的错误消息。 我不确定它应该是什么包,以及如何解决它。

它为我提供的错误信息是:

ERROR  Failed to compile with 1 errors                                 19:09:01

未找到此依赖项:

* @/services/PostsService in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/Posts.vue

    To install it, you can run: npm install --save @/services/PostsService

我的 package.json 看起来像这样

{
  "name": "server",
  "version": "5.3.0",
  "description": "",
  "main": "src/app.js",
  "scripts": {
    "start": "./node_modules/nodemon/bin/nodemon.js src/app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.4",
    "express": "^4.16.3",
    "morgan": "^1.9.0",
    "nodemon": "^1.17.3"
  }
}

我的 posts.vue 看起来像这样

<template>
  <div class="posts">
    <h1>Posts</h1>
    This file will list all the posts.

    <div v-for="post in posts">
      <p>
        <span><b>{{ post.title }}</b></span><br />
        <span>{{ post.description }}</span>
      </p>
    </div>
  </div>
</template>

<script>
import PostsService from '@/services/PostsService'
export default {
  name: 'posts',
  data () {
    return {
      posts: []
    }
  },
  mounted () {
    this.getPosts()
  },
  methods: {
    async getPosts () {
      const response = await PostsService.fetchPosts()
      this.posts = response.data
    }
  }
}
</script>

我的 PostService.js 具有以下内容

import Api from '@/services/Api'

export default {
  fetchPosts () {
    return Api().get('posts')
  }
}

0 个答案:

没有答案