vue中forEach循环的使用讲解

  getCrumbs(){

  let crumbs = JSON.parse(localStorage.getItem( "crumbs" ));

  //[Vue warn]: Error in created hook: "TypeError: Cannot set property 'manageClass' of undefined" 报错

  // crumbs.forEach(function(item){

  crumbs.forEach(item => {

  console.log(item);

  if (item.name === "staffInfo") {

  this.manageClass = item.manageClass

  this.infoClass = item.infoClass;

  }

  })

  // 或者使用for循环

  for (let i = 0; i < crumbs.length; i++) {

  if (crumbs[i].name === "staffInfo") {

  this.manageClass = crumbs[i].manageClass

  this.infoClass = crumbs[i].infoClass;

  }

  }

  },