Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基本CRUD返回404(MySQL&x2B;Express&x2B;VueJS+;NodeJS)_Mysql_Node.js_Express_Vue.js - Fatal编程技术网

基本CRUD返回404(MySQL&x2B;Express&x2B;VueJS+;NodeJS)

基本CRUD返回404(MySQL&x2B;Express&x2B;VueJS+;NodeJS),mysql,node.js,express,vue.js,Mysql,Node.js,Express,Vue.js,我做了以下示例:我的连接断开了 我只能在浏览器中看到此错误: GET http://localhost:8080/api/pedidos 404 (Not Found) 我唯一的一个修改是更改表以添加一列 myserver.js var express = require("express") var bodyParser = require("body-parser") var pedidos = require("./routes/pedidos") var cors = require

我做了以下示例:我的连接断开了

我只能在浏览器中看到此错误:

GET http://localhost:8080/api/pedidos 404 (Not Found)
我唯一的一个修改是更改表以添加一列

myserver.js

var express = require("express")
var bodyParser = require("body-parser")

var pedidos = require("./routes/pedidos")
var cors = require("cors")

var port = 3000

var app = express()
app.use(cors())

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))

app.use("/api", pedidos)

app.listen(port, function () {
    console.log('Server started on port >>> ' + port)
})
我的开发人员网页包配置:

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',

    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    proxyTable: {
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        logLevel: 'debug'
      }
    },
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

  }
我的pedidos.js

var express = require("express")
var router = express.Router()
const Pedido = require("../model/Pedido")

//Get All pedidos
router.get("/pedidos", (req, res) => {
    Pedido.findAll()
        .then(pedidos => {
            res.json(pedidos)
        })
        .catch(err => {
            res.send("error: " + err)
        })
})

module.exports = router

您是否重新启动了前端服务器,vue.config.js change需要重新启动,方法是运行“纱线服务”

粘贴
pedidos
路由。port=3000,但//localhost:8080/api/pedidos有8080?
应用程序。使用(“/api”,pedidos)
,具体显示路由代码。还要检查您的路由是否正确接受新的mysql模式。我已经从路由中添加了pedidos.js。您的vue项目是如何创建的?我看你发的视频。它看起来像是用vue cli 2.x创建的!您需要使用相同的版本。看起来我需要在不同proxyTable设置的测试时间后重新启动vue文件配置。是的!它无法自动重新启动。