Data Interaction modes of several vue and vue interaction modes
Var that = this
Get request
That. $ http. get ("1.txt"). then (function (result ){
Console. log (result)
This. msg = result. data;
})
Post requests require the environment to send data to receive data
That. $ http. post ("1.txt"," "). then (function (result ){
Console. log (result)
})
Comprehensive request
That. $ http ({
Method: "get ",
Url: "1.txt"
}). Then (function (result ){
Console. log (result. data)
})
Es6 Request method: whether the cache is reloaded or not
Fetch ("url", {method: "get", cache: "reload"}). then (function (){
})
Vue2 request
Axios ({
Url :"Www.baidu.com? PageStart = 18 pageSize = 3",
Method: "get/post ",
If it is a get request, use params to transmit data or splice the address bar
Params :{
PageStart: 1,
PageSize: 3
}
Use data to transmit data for post requests
Data :{
}
})
Instance
Baidu cross-origin request
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 cross-origin requests
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 )})