vue cli4,其他版本脚手架也可以使用的原生axios
调用post请求控制台报错Access to XMLHttpRequest at ‘http://1xxxxxx/license/public/admin/order/login’ from origin ‘http://localhost:8080’ has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response
index.html引入axios
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
在vue 项目中 例如post请求
axios
.post("http://xxxxxxxxxxxxxxxxxxxxxxxxx", {
account: "xxxxxx",
password: "xxxxxxx"
},{
headers: {'Content-Type': 'application/x-www-form-urlencoded'} //请求头
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
这样基本数据就会出来