首页 > 其他 > 详细

Vue vue-resource 请求数据

时间:2019-06-20 14:08:06      阅读:139      评论:0      收藏:0      [点我收藏+]
<template>
    <!-- 所有的内容要被根节点包含起来 -->
    <div id="home">
         首页组件


        <button @click="getData()">请求数据</button>

        <hr>
        <br>

        <ul>
            <li v-for="item in list">
            
                {{item.title}}
            </li>
        </ul>
    </div>

</template>


<script>

/*

请求数据的模板

    vue-resource  官方提供的 vue的一个插件


    axios


    fetch-jsonp
*/
   

    export default{
        data(){
            return {

                msg:我是一个首页组件msg,
                flag:true,
                list:[]
            }
        },
        methods:{

            getData(){
                    //请求数据

                    var api=http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1;


                    this.$http.get(api).then((response)=>{
                        console.log(response);

                        //注意this指向

                        this.list=response.body.result;



                    },function(err){

                            console.log(err);

                    })

            }
        },
        mounted(){  /*生命周期函数*/

                this.getData();

        }
       

    }

</script>

<style lang="scss" scoped>

    /*css  局部作用域  scoped*/

    h2{

        color:red
    }

    
</style>

 

Vue vue-resource 请求数据

原文:https://www.cnblogs.com/loaderman/p/11058156.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!