vue. js sample method for implementing request data
- 2021-07-18 06:25:32
- OfStack
The sample code for vue 2.0 is as follows:
var vm = new Vue({
el:"#list",
data:{
gridData: "",
},
mounted: function() {
this.$nextTick(function () {
this.$http.jsonp('http://***.com').then(function(res) {
console.log(res.data)
this.gridData = res.data;
})
})
},
})
vue 2.0 discarded the method defined by ready and replaced it with mounted, but added
this.$nextTick(function(){})
.
If no request succeeds, see the version of vuejs under 1
Version 1.0 is written like this
var vm = new Vue({
el:"#list",
data:{
gridData: '',
},
ready: function() {
this.$http.jsonp('http://***.com').then(function(res){
this.$set('gridData', res.data);
})
},
})
Summarize
The above is all about the data requested by vue. js. I hope the content of this article can bring 1 certain help to your study or work. If you have any questions, you can leave a message for communication.