大神们 这个报错该怎么解决
import { request } from "../../request/index.js";
Page({
data: {
// 左侧的菜单数据
leftMenuList:[],
// 右侧的商品数据
rightContent:[],
//被点击的左侧的菜单
currentIndex:0
},
// 接口的返回数据
Cates:[],
onLoad:function(options){
this.getCates();
},
// 获取分类数据
getCates(){
request({
url:"https://api-hmugo-web.itheima.net/api/public/v1/categories"
})
.then(res => {
this.Cates=res.data.message;
// 构造左侧的大菜单数据、
let leftMenuList=this.Cates.map(v=>v.cat_name)
// 构造右侧的商品数据
let rightContent=this.Cates[0].children;
this.setData({
leftMenuList,
rightContent
})
})
},
//左侧菜单的点击事件
handleItemTap(e){
// 1 获取被点击的标题身上的索引
// 2 给data中的curreetIndex赋值就可以了
const {index}=e.currentTarget.dataset;
this.setData({
currentIndex: index
})
}
})
就是你的index是空的,自己排查一下
你打印下index呢,看看是不是undefined