亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請教各位前輩,vue-cli可以跨域拿到豆瓣的數據,為什么不能跨域拿到本地數據庫的數據呢?

請教各位前輩,vue-cli可以跨域拿到豆瓣的數據,為什么不能跨域拿到本地數據庫的數據呢?

慕工程0101907 2019-05-21 11:11:38
嘗試用vue-cli來獲取本地服務器數據庫的數據但返回以下錯誤提示,用同樣的寫法卻可以獲取豆瓣的數據。折騰來一個晚上無法解決,希望前輩們能抽空指點!不勝感激![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)//啟動路由/*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)})}}后臺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)
查看完整描述

2 回答

?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

感謝各位前輩關注和解答,最后我用了以下辦法來解決
1、安裝
npminstall--save-devconcurrently
2、將package.json的script加上
"server":"nodeserver.js",
"go":"concurrently--kill-others\"npmrundev\"\"npmrunserver\""
3、輸入命令
npmrungo
然后就可以了
                            
查看完整回答
反對 回復 2019-05-21
  • 2 回答
  • 0 關注
  • 588 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號