国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

node.js - vue-resource,如何改變響應(yīng)格式?

瀏覽:170日期:2023-10-01 18:46:07

問題描述

使用vue-resource 發(fā)送一個get請求,響應(yīng)數(shù)據(jù)是文本,卻接收到的數(shù)據(jù)是blob類型。請問怎么破?

node.js 服務(wù)器代碼:

router.get(’/’,function (req, res, next) {

var data = querystring.parse(url.parse(req.url).query); res.sendfile('./public/song/'+data.lyric,’utf8’);

})

vue-resource 代碼:

this.$http.get(url)

.then(function (res) { console.log(res.body); })

響應(yīng)內(nèi)容:node.js - vue-resource,如何改變響應(yīng)格式?node.js - vue-resource,如何改變響應(yīng)格式?

問題解答

回答1:

抱歉,express和vue-resource都是不會很熟

嘗試更改服務(wù)端代碼,指定頭部

router.get(’/’,function (req, res, next) { var data = querystring.parse(url.parse(req.url).query);res.sendfile('./public/song/'+data.lyric,{headers:{ ’content-type’:’text/plain’} });})

我沒記錯的話vue-resource的res是text這個屬性的

this.$http.get(url) .then(function (res) {console.log(res.text); })

建議換用superagent或者axios

回答2:

我沒記錯的話,res.data才是響應(yīng)過來的數(shù)據(jù)

標(biāo)簽: vue
主站蜘蛛池模板: 北票市| 永城市| 婺源县| 唐河县| 大姚县| 二连浩特市| 汶上县| 衡阳县| 屯门区| 临安市| 安仁县| 凤山县| 哈密市| 叶城县| 綦江县| 盘山县| 东乌珠穆沁旗| 教育| 宁晋县| 庆元县| 神农架林区| 布拖县| 云梦县| 诸城市| 唐海县| 双桥区| 福建省| 鄂温| 北碚区| 犍为县| 长治县| 福海县| 宕昌县| 清苑县| 香格里拉县| 响水县| 秦安县| 临潭县| 大丰市| 太湖县| 岗巴县|