vue.js 请求数据

VUE.JS

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;
                    })
                })
            },
        })

vue2.0版本废弃了ready定义的方法,使用mounted来代替,不过需要加上this.$nextTick(function(){})。

如果没有请求成功看一下vuejs的版本,1.0版本的写法是这样的

var vm = new Vue({
    el:"#list",
    data:{
        gridData: '',
    },
    ready: function() {
        this.$http.jsonp('http://***.com').then(function(res){
            this.$set('gridData', res.data);
        })
    },
})
原文地址:https://www.cnblogs.com/chengjunL/p/6169071.html