<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>VUE ajax案例</title>
<script src="js/vue.js"></script>
<script src="js/vue-resource.min.js"></script>
</head>
<body>
<div id="box">
<input type="button" @click="get()" value="Click Me" />
</div>
<script>
window.onload=function(){
var vm=new Vue({
el:'#box',
data:{msg:'Hello World'},
methods:{
get:function(){
//发送get请求
this.$http.get('ajax.txt').then(function(res){
document.write(res.body);
},function(){
console.log('请求处理失败')
});
}
}
})
}
</script>
</body>
</html>

 VUE ajax_ajax跨域问题


VUE ajax_html_02