和教学视频相同的几行代码报错了怎么办?
发布于 6 年前 作者 taoyang 1813 次浏览 来自 问答

       

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

以下是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: http://wthrcdn.etouch.cn/weather_mini?city=西安, //仅为示例,并非真实的接口地址

data: {

x: ‘’,

y: ‘’

},

header: {

‘content-type’: ‘application/json’ // 默认值

},

success: function (res) {

console.log(res);

/*

        *var future=res.data.data.forecast;

        *var todayInfo=future.shift();

        *var today=res.data.data;

        *today.todayInfo=todayInfo;

        *page.setData({today:today,future=future});

        */

}

})

}

})

/*

*以下是wxml代码

*/

<view class=‘content’>

<view class=‘today’>

<view class=“info”>

<view class=‘temp’>{{today.wendu}}25°C</view>

<view class=‘weather’>晴朗 东风2~3级</view>

<view>友情提示:天气晴朗,阳光明媚,适合外出</view>

<view class=“city”>{{city}}

</view>

</view>

</view>

<view class=‘future’>

</view>

</view>

折磨我好久了,求大神指点!

回到顶部