节点 webpack 开发服务器在 vuejs 项目中失败“无法获取/" [英] Node webpack dev server failing 'Cannot GET /' in vuejs project

查看:20
本文介绍了节点 webpack 开发服务器在 vuejs 项目中失败“无法获取/"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过 webpack 运行我的节点开发服务器时,我的浏览器打印出一条非常无用的消息无法获取/".我正在使用以下内容构建 Vuejs 应用程序:

I am getting a super unhelpful message 'Cannot GET /' printed to my browser when I run my node dev server through webpack. I am building a Vuejs application with the following:

  • VueJs structured in a way that was dicated by this Vue Template with my node scripts being identical to the default commands
  • Webpack config based on Vue Loader
  • Routes handled through Vue Router

我知道这不是什么大不了的事情,但是如果知道是什么引发了这个错误(Node?Webpack?Vue Router?),它会为我指明正确的方向,我将不胜感激.

I know this is not a great deal to go off but an idea of what is firing this error (Node? Webpack? Vue Router?) it would point me in the right direction and be greatly appreciated.

推荐答案

我发现自己遇到了同样的问题.就我而言,它与 ExpressVue.js 的使用有关.所以我会留下我的解决方案,以防有人觉得它有用

I found myself in the same problem. In my case it was related to the use of Express with Vue.js. So I am leaving my solution in case anyone finds it useful

我添加了这段代码来处理对我的 index.html 文件的调用

I added this code for handling the calls to my index.html file

app.route('/*')
    .get(function(req, res) {
          res.sendFile(path.join(__dirname + '/dist/index.html'));
});

module.exports = app;

这篇关于节点 webpack 开发服务器在 vuejs 项目中失败“无法获取/"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆