1. 程式人生 > >vue 請求後臺數據 (copy)

vue 請求後臺數據 (copy)

art cal .html http html txt HA url jsonp

https://www.cnblogs.com/calledspeed001/p/7094494.html

var that=this

get請求

that.$http.get("1.txt").then(function(result){

console.log(result)

this.msg=result.data;

})

post請求 需要環境 發送數據 接收數據

that.$http.post("1.txt","").then(function(result){

console.log(result)

})

綜合性請求

that.$http({

method:"get",

url:"1.txt"

}).then(function(result){

console.log(result.data)

})

es6請求 method 請求方式 cache 是否緩存是否重新加載

fetch("url",{method:"get",cache:"reload"}).then(function(){

})

vue2 請求

axios({

url:"www.baidu.com?pageStart=18pageSize=3",

method:"get/post",

如果是get請求的話 用params 來傳輸數據或者地址欄拼接

params:{

pageStart:1,

pageSize:3

}

如果是post請求的話 用data去傳輸數據

data:{

}

})

實例

百度跨域請求

var that=this;

that.$http.jsonp("https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su",{wd:this.abc},{jsonp:"cb"}).then(function(result){

console.log(result.data.s)

})

360跨域請求

that.$http.jsonp("https://sug.so.360.cn/suggest?encodein=utf-8&encodeout=utf-8",{word:this.abc},{emulateJSON:true}).then(function(result){

console.log(result.data.s)})

vue 請求後臺數據 (copy)