嘗試用vue-cli來獲取本地服務(wù)器數(shù)據(jù)庫的數(shù)據(jù)但返回以下錯(cuò)誤提示,用同樣的寫法卻可以獲取豆瓣的數(shù)據(jù)。折騰來一個(gè)晚上無法解決,希望前輩們能抽空指點(diǎn)!不勝感激![HPM]Erroroccurredwhiletryingtoproxyrequestfromlocalhost:8080tohttp://localhost:3000(ECONNREFUSED)(https://nodejs.org/api/errors.html#errors_common_system_errors)我的代碼部分config->index.jsproxyTable:{'/api':{target:'http://localhost:3000',changeOrigin:true,pathRewrite:{'^/api':''}}src->main.jsimportVuefrom'vue'importAppfrom'./App'importVueRouterfrom'vue-router'importrouterConfigfrom'./router.config.js'//引入路由importAxiosfrom'axios'Vue.config.productionTip=false;Vue.prototype.$axios=Axios;Vue.prototype.HOST='/api';Vue.use(VueRouter);constrouter=newVueRouter(routerConfig)//啟動(dòng)路由/*eslint-disableno-new*/newVue({el:'#app',router,//掛載路由components:{App},//組件名template:'',})src->App.vueexportdefault{created(){varurl=this.HOSTthis.$axios.get(url,{}).then((res)=>{console.log(res.data)},(res)=>{alert(res.status)})}}后臺(tái)serverconstexpress=require('express');constmysql=require('mysql');constdb=mysql.createPool({localhost:'localhost',user:'root',password:'123456',database:'blog'})constserver=express();server.use('/api',(req,res)=>{db.query(`SELECT*FROMarticles_table`,(err,data)=>{if(err){console.error(err);res.status(500).send('databaseerror').end();}else{res.send(data)}})})server.listen(3000)
請(qǐng)教各位前輩,vue-cli可以跨域拿到豆瓣的數(shù)據(jù),為什么不能跨域拿到本地?cái)?shù)據(jù)庫的數(shù)據(jù)呢?
慕工程0101907
2019-05-21 11:11:38