<view> {{title}} </view>
<span style="font-size:24px;"><!--index.wxml-->
<view class="container">
<view style="color:{{red}}">{{city_name}}</view>
<view>{{date}}</view>
<view>{{info}}</view>
</view></span>
var app = getApp();
var that;
var Util = require( '../../utils/util.js' );
Page( {
data: {
city_name: '',
title:'',
red:'green'
},
onLoad: function(options) {
this.setData({
title:options.title
})
that = this;
wx.request( {
url: "http://op.juhe.cn/onebox/weather/query",
header: {
//请求头和ajax写法一样
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
data: Util.json2Form( { cityname: "北京", key: "1430ec127e097e1113259c5e1be1ba70" }),
complete: function( res ) {
wx.showToast({
title:'成功',
icon:'success',
duration:2000
})
that.setData( {
red:'red',
city_name: res.data.result.data.realtime.city_name,
date: res.data.result.data.realtime.date,
info: res.data.result.data.realtime.weather.info,
});
if( res == null || res.data == null ) {
console.error( '网络请求失败' );
return;
}
setTimeout(function(){
wx.hideToast()
},2000)
}
})
}
})
function json2Form(json) {
var str = [];
for(var p in json){
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));
}
return str.join("&");
}
module.exports = {
formatTime: formatTime,
json2Form:json2Form,
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有