Open C-Rachel opened 7 years ago
可以使用vue-resource实现ajax
全局使用 Vue.http.get().then()
局部使用 this.$http.get().then()
DEMO
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript" src="js/vue-resource.js" ></script>
<script>
new Vue({
el: "#demo",
data: {
name: "yao",
arr: ["xu", "chan", "ly"],
},
methods:{
test:function(){
console.log(111)
this.$http.get('data/data.json').then(function(data){
console.log(data.body[0].name);
console.log(this)
console.log(this.$el)
});
}
}
})
</script>
vue+zepto vue+jQuery $.ajax()实现请求
Vue不像angular js 一样封装了ajax ( $http ),所以需要自己写,也可以配合插件使用
ajax函数中的this指向的是demo对象的,所以需要
var self = this;
保存对demo的指向,然后里面的写法就是原生JS的ajax写法了php代码简单写
这样就可以在Vue实现ajax请求了