axios的初步使用

1、数据格式

[
    {
        "title": "喵1",
        "href": "1",
        "url": "Images/1.jpg"
    },
    {
        "title": "喵2",
        "href": "2",
        "url": "Images/2.jpg"
    },
    {
        "title": "喵3",
        "href": "3",
        "url": "Images/3.jpg"
    }
]

2、取值方法

getPic:function(){
        // 也可以通过 params 对象传递参数
            axios.get('Data/goPics.json', {
                params: {
                //ID: 12345
                },
                 responseType: 'json', // default
            })
            .then(function (response) {
                this.pic=response;
              alert(this.pic.data[0].url);//这里需要注意,json数据中并没有data这一层,是控件添加的,取得时候需要加上data
            })
            .catch(function (error) {
                console.log(error);
            });
        }

 

posted @ 2017-05-09 21:35  HongMaJu  阅读(252)  评论(0编辑  收藏  举报