ajax+vue简单使用

<script type="text/javascript" src="http://cdn.bootcss.com/vue/2.2.2/vue.min.js">

\<script>
    new Vue({
    el: '#app',
    data: {
        sites: [
        { name: 'Runoob' },
        { name: 'Google' },
        { name: 'Taobao' }
        ]
    }, 
    created:function () {
        var self = this;
        $.ajax(
            {
                url:'http://127.0.0.1:8000/news/newsapi/',
                type:'GET',
                data:{
                    'format': 'json',
                    'page': 1,
                },
                dataType:"json",
                timeout:'1000',
            }
        ).then(function (res) {
            console.log(res)
            console.log(self.sites)
        }).fail(function () {
            console.log('失败');
        })
    }
    });
\</script>

猜你喜欢

转载自www.cnblogs.com/vinic-xxm/p/11707151.html