ReferenceError: res is not defined at pi.onLoad (teachers.js? [sm]:32) at pi.<anonymous> (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1) at pi.s.__callPageLifeTime__ (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1) at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at Function.br (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1)(env: Windows,mp,1.06.2308310; lib: 3.1.0)
ReferenceError: res is not defined at pi.onLoad (teachers.js? [sm]:33) at pi.<anonymous> (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1) at pi.s.__callPageLifeTime__ (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1) at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1 at Function.br (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1)(env: Windows,mp,1.06.2308310; lib: 3.1.0)
this.setData({ list: res.data })
<view wx:for="{{list}}" wx:key="index"> <view>{{item.name}}</view> <view>{{item.sex}}</view> </view>
at pi.onLoad (teachers.js? [sm]:32)
at pi.<anonymous> (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1)
at pi.s.__callPageLifeTime__ (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1)
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at Function.br (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1)(env: Windows,mp,1.06.2308310; lib: 3.1.0)
报错显示res没定义,怎么定义啊?
所有的数据都必须通过 this.setData 才能在 wxml 渲染,微信js逻辑和渲染层是分开的,需要手动 setData 传送数据到渲染层进行渲染,js 访问这个数据用 this.data.xx
比如你获取页面轮播图数据
js:
var that = this; that.setData({ banners:res.data })
wxml:
<view class="banner"> <swiper autoplay="true" circular="true" duration="1000" indicatorActiveColor="#fff" indicatorColor="#3e84bf" indicatorDots="true" interval="2500" style="height:{{Hei}}"> <swiper-item wx:for="{{banners}}" wx:key="*this"> <navigator url="{{item.url}}"> <image bindload="imgH" class="slide-image" mode="widthFix" src="{{item.image}}"></image> </navigator> </swiper-item> </swiper> </view>
at pi.onLoad (teachers.js? [sm]:33)
at pi.<anonymous> (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1)
at pi.s.__callPageLifeTime__ (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1)
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1
at Function.br (WASubContext.js?t=wechat&s=1695709943890&v=3.1.0:1)(env: Windows,mp,1.06.2308310; lib: 3.1.0)
我试了下,报了这么个错。
//发送请求连接,获取数据
wx.request({
url: 请求连接;
success(res) {
self.setData({
banners: res.data.data
})
}
})
db.collection("teachers")
.get() //获取根据查询条件筛选后的集合数据
.then(res => {
console.log(res.data)
this.setData({
//比如wxml中是list
list: res.data
})
})