收藏
回答

Setting data field"currentIndex"to undefined怎么解决?

AppID
wx12cdb338de21c6c3

大神们 这个报错该怎么解决


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

    })

  }

 

})


回答关注问题邀请回答
收藏

2 个回答

  • showms
    showms
    1天前

    就是你的index是空的,自己排查一下

    1天前
    有用
    回复 2
  • 小黎
    小黎
    2天前

    你打印下index呢,看看是不是undefined

    2天前
    有用
    回复 1
登录 后发表内容