export default {
data () {
return {
urlData: []
}
},
mounted () {
this.getData()
},
methods: {
// XmlHttpRequest对象
createXmlHttpRequest () {
if (window.ActiveXObject) { //如果是IE浏览器
// eslint-disable-next-line no-undef
return new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) { //非IE浏览器
return new XMLHttpRequest();
}
},
// 请求数据
getData (searchObj) {
let self = this
var xhr = this.createXmlHttpRequest();
xhr.open('GET', 'http://localhost:7777/supply/viewData', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function () {
let result = JSON.parse(this.response)
self.urlData = result.data
}
xhr.send(null);
}
}
}
}
利用XMLHttpRequest发起请求解决跨域
最新推荐文章于 2024-05-08 00:18:50 发布