Ask your predecessors, vue-cli can cross-domain access to Douban data, why not cross-domain access to the local database data?

try to use vue-cli to get the data of the local server database, but return the following error prompt, but you can get the data of Douban in the same way. It can"t be solved all night. I hope the seniors can take the time to give us some advice! Thank you very much!

[HPM] Error occurred while trying to proxy request  from localhost:8080 to http://localhost:3000 (ECONNREFUSED) (https://nodejs.org/api/errors.html-sharperrors_common_system_errors)

part of my code
config-> index.js

proxyTable: {
    "/api":{
        target: "http://localhost:3000",
        changeOrigin: true,
        pathRewrite: {
        "^/api": ""
        }
     }

src-> main.js

import Vue from "vue"
import App from "./App"
import VueRouter from "vue-router"
import routerConfig from "./router.config.js" //
import Axios from "axios"


Vue.config.productionTip = false;
Vue.prototype.$axios = Axios;
Vue.prototype.HOST = "/api";

Vue.use(VueRouter);

const router = new VueRouter(routerConfig) //

/* eslint-disable no-new */
new Vue({
  el: "-sharpapp",
  router,  //
  components: { App }, // 
  template: "<App/>",
})

src-> App.vue

export default{

  created(){
    var url = this.HOST
    this.$axios.get(url,{

    }).then((res)=>{

     console.log(res.data)

    },(res)=>{

    alert(res.status)
  })
  }
}

background server

const express = require("express");
const mysql = require("mysql");

const db = mysql.createPool({
  localhost:"localhost",
  user:"root",
  password:"123456",
  database:"blog"
})

const server = express();

server.use("/api",(req,res)=>{

    db.query(`SELECT * FROM articles_table`,(err,data)=>{
       if(err){
         console.error(err);
         res.status(500).send("database error").end();
       }else{
         res.send(data)
       }
    })

})

server.listen(3000)


Thank you for your attention and answers. Finally, I used the following methods to solve

1, install

npm install --save-dev concurrently

2. Add the script of package.json

"server": "node server.js",
"go": "concurrently --kill-others \"npm run dev\" \"npm run server\""

3, enter the command

npm run go

then you can do it


since you can get Douban's data, it proves that what you wrote in the front part must be correct. I looked at your back-end code and found that you used exoress, but did not seem to listen to port 3000. To listen to the port is to open server.


Douban API enables cross-domain by default, because open API, does not cross-domain generally requires a server-side technical secondary school. It's troublesome


reference: https://blog.csdn.net/dreamer.
try the header data returned by setting the server


because some websites now enable cross-domain settings by default. Make the interface accessible even across domains


you proxy / api to local port 3000, request the / api interface on the port, use / api/api. Try


maybe your local api does not enable cross-domain. Now it is recommended to use cors to solve cross-domain problems

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2b871-2ba99.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2b871-2ba99.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?