上图中的红色区域代码部分与小木学堂视频中的代码一模一样,但是开发者工具版本不一样。请问为什么我编译会报错?该怎么解决?我将该部分代码去掉(加上注释),则可以编译成功,其他代码的功能可以实现。如下图:



以下是js和wxml的源代码:


Page({

/**

  * 页面的初始数据

  */

data: {

city:"",

today:{},

future:{}

},


/**

  * 生命周期函数--监听页面加载

  */

onLoad: function (options) {

this.loadInfo();

},


/**

  * 生命周期函数--监听页面初次渲染完成

  */

onReady: function () {

},


/**

  * 生命周期函数--监听页面显示

  */

onShow: function () {

},


/**

  * 生命周期函数--监听页面隐藏

  */

onHide: function () {

},


/**

  * 生命周期函数--监听页面卸载

  */

onUnload: function () {

},


/**

  * 页面相关事件处理函数--监听用户下拉动作

  */

onPullDownRefresh: function () {

},


/**

  * 页面上拉触底事件的处理函数

  */

onReachBottom: function () {

},


/**

  * 用户点击右上角分享

  */

onShareAppMessage: function () {

},

loadInfo: function(){

var page=this;

wx.getLocation({

type: 'gcj02', //返回可以用于wx.openLocation的经纬度

success: function (res) {

var latitude = res.latitude;

var longitude = res.longitude;

console.log(latitude,longitude);

page.loadCity(latitude,longitude);

}

})

},

loadCity:function(latitude,longitude){

var page = this;

wx.request({

url: 'http://api.map.baidu.com/geocoder/v2/?ak=arkRAvFzRAbKWcBsMtaWC9Zz1qALwCiS&location=34.34127,108.93984&output=json', //仅为示例,并非真实的接口地址

data: {

x: '',

y: ''

},

header: {

'content-type': 'application/json' // 默认值

},

success: function (res) {

console.log(res);

var city=res.data.result.addressComponent.city;

city=city.replace("市","");

page.setData({city:city});

page.loadWeather(city);

}

})

},

loadWeather:function(city){

var page = this;

wx.request({

url:

展开全部
收起
0回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部