微信小程序 进阶之路(2)

ip查询接口:

loadip:function(){
    wx.request({
      url: 'http://ip-api.com/json',
      success: function (e) {
        console.log(e.data);
      }
    })
    
  }

同级函数间调用:

  this.loadip();

动态渲染数据:

 success(res) {
        console.log(res.data);
        var aa={
          area:res.data.result.area,
          city: res.data.result.city,
          country:res.data.result.country,
          province:res.data.result.province,
          ip: res.data.result.ip,
          type: res.data.result.type
        }
        this.setData(aa);
        }

ip归属地查询:

jisu:function(e){
    this.loadip();
    var _this=this;
    var name=this.data.user
    console.log(name);
    wx.showToast({
      title: '确定',
      icon: 'success',
      duration: 2000
    })
    wx.request({
      url: 'https://api.jisuapi.com/ip/location?appkey=yourappkey&ip=210.21.28.34', //急速数据
      header: {
        'content-type': 'application/json' 
      },
      success(res) {
        console.log(res.data);
        var aa={
          area:res.data.result.area,
          city: res.data.result.city,
          country:res.data.result.country,
          province:res.data.result.province,
          ip: res.data.result.ip,
          type: res.data.result.type
        }
        _this.setData(aa);
        }
    })}

弹性布局:
wxml:

<cover-view class="dall">
<cover-view class="dal">
<cover-view wx:for="{{iconUrl}}" class='da' wx:key="icon" wx:for-index="idx">
<cover-view class="dao">
<cover-view class="dao1">
<cover-view class="dao3" bindtap='indexto' >
<cover-image src='{{item.at}}' class="imgh" data-id="{{idx}}"></cover-image>
</cover-view>
</cover-view>
<cover-view class="dao2">
<cover-view class="dao4">{{item.bt}}</cover-view>
</cover-view>
</cover-view>
</cover-view>
</cover-view>
</cover-view>

wxcs:

.dao1{
  flex-basis: 60%;
  display: flex;
  height: 60%;
  justify-content: center;
  align-items: center;
}
.dao2{
  flex-basis: 70%;
  display: flex;
  height: 30%;
  justify-content: center;
  align-self: flex-end;
  font-size: 80%;
}
.imgh{
  height: 100%;
  width: 80%;
}
.dao4{
  display: flex;
}
.dall{
  width: 100%;
  display: flex;
  height: 400rpx;
  justify-content: center;
  align-items: center;
}
.dao3{
  display: flex;
  width: 55%;
  height: 60%;
  justify-content: center;
  align-items: center;

}
.dal{
  display: flex;
  flex-basis: 90%;
  height:90%;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.da{
  display: flex;
  justify-content: center;
  align-items: center;
  flex-basis: 33.33%;
  height: 50%;
}
.dao{
  display: flex;
  flex-basis: 100%;
  height: 100%;
  flex-wrap: wrap;
  justify-content: center;
  align-content: space-between;

}

设置索引(上面代码有展示):

wx:for-index="idx"
data-id="{{idx}}"

js根据相应的值跳转不同的页面:

indexto:function(e){
    var id = e.target.dataset.id;;
    switch(id){
      case 0:
        wx.navigateTo({
          url: '/pages/account/my',
        });
      case 1:
        wx.navigateTo({
          url: '/pages/recodes/recode',
        });
      case 2:
        wx.navigateTo({
          url: '/pages/arreas/aa',
        });
       case 3:
        wx.navigateTo({
          url: '/pages/help/use',
        });
       case 4:
        wx.navigateTo({
          url: '/pages/rechanrge/bill',
        });
       case 5:
        wx.navigateTo({
          url: '/pages/query/transit',
        });
    }
  }

将数据封装成一个数组:

 iconUrl:[
      {at: '../images/a.png', bt: '我的帐户',},
      {at: '../images/b.png', bt:'乘车记录'},
      {at: '../images/c.png', bt: '缴清欠款'},
      {at: '../images/d.png', bt: '使用帮助'},
      {at: '../images/e.png', bt:'话费充值'},
      {at: '../images/f.png', bt:'ip查询'},
    ]

渐变色:

  background:linear-gradient(to top,#6f6fb1,#3a74da) ;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值