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)