request ajax axios
await asnyc promise
跨域
1vue-resource
vue将不再支持
参考https://blog.csdn.net/weixin_34401479/article/details/90155465
this.$http.get(url).then((res)=>{})
this.$http.get(url,{params : {a:1,b:2}}).then((res)=>{})
2axios
https://www.runoob.com/vue2/vuejs-ajax-axios.html
https://www.runoob.com/vue3/vue3-ajax-axios.html
axios.get()
axios.baseUrl
3
4
5
6jsonp
https://www.runoob.com/json/json-jsonp.html
以下代码会运行callbackFunction
页面会显示数据
<body>
<div id="divCustomers"></div>
<script type="text/javascript">
//jsonp.php文件
/* <?php
header('Content-type: application/json');
//获取回调函数名
$jsoncallback = htmlspecialchars($_REQUEST ['jsoncallback']);
//json数据
$json_data = '["customername1","customername2"]';
//输出jsonp格式的数据
echo $jsoncallback . "(" . $json_data . ")";
?>*/
function callbackFunction(result, methodName)
{
var html = '<ul>';
for(var i = 0; i < result.length; i++)
{
html += '<li>' + result[i] + '</li>';
}
html += '</ul>';
document.getElementById('divCustomers').innerHTML = html;
}
</script>
<script type="text/javascript" src="https://www.runoob.com/try/ajax/jsonp.php?jsoncallback=callbackFunction"></script>
</body>