安装vue-resource,axios数据请求

一、vue-resource数据请求

1.cd 到项目中 执行 cnpm install vue-resource --save

2.在main.js中引入  import VueResource from './vue-resource'

                        使用       Vue.use(VueResource)

使用如:在methods中写方法:

getData(){
            var api = 'http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1';
            // this.$http.get(api).then(function(res){
            this.$http.get(api).then((res)=>{
                console.log(res.body.result)
                this.list = res.body.result
            },function(err){
                console.log(err)
            })
        }

二、axios数据请求

1.cd到项目中 执行cnpm install axios --save

2.哪个组件用到则在哪个组件的script中引入   import Axios from 'axios';

使用如:methods中写方法:

getData1(){
        var api = 'http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1';
        Axios.get(api,{token:token}).then((res)=>{
            console.log(res.data.result)
            this.list=res.data.result
        }).catch((err)=>{
            console.log(err)
        })
    },

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值