最近用的vue請求數據,坑死,仍是對前端vue框架不熟。前端
與後端通訊有問題,要麼是json加入到url有問題、要麼是json解析有問題。vue
解決方法:ios
一、請求參數一個用url傳web
var json=[{"msg」:「123"}]; var temp=encodeURI(JSON.stringify(json)); //重點 var urls="http://202.114.207.232:8080/web/data?operations="+temp; this.$axios({type:'post',url:urls, dataType:'json' }).then( res => { console.log(res) }).catch( e => { console.info(e) })
二、一個用data包裝傳json
var Data=[{}] var url = "http://111.111.111.111:8080/web/data"; var params = new URLSearchParams(); params.append("operations", JSON.stringify(Data)); //重點 // params.append('param2', 'value2'); that.$axios.post(url, params) .then(response => { // post 成功,response.data 爲返回的數據 console.log(response.data) }) .catch(error => { // 請求失敗 console.log(error) })