首页 >社区问答列表 >javascript - export default中的data选项设置了值,但是获取不到

javascript - export default中的data选项设置了值,但是获取不到

<script>
import BScroll from 'better-scroll';

const ERR_OK=0;
export default{
  prop:{
    seller:{
    type:Object
    }
  },
  data(){
    return{
        goods:[],
        listHeight:[],
        scrollY:1
    };
  },
  computed:{
    currentIndex(){
      for(let i=0;i<this.listHeight.length;i++){
        let height1=this.listHeight[i];
        let height2=this.listHeight[i+1];
        if(!height2||this.scrollY>=height1&&this.scrollY<height2){
          return i;
        }
      }
      return 0;
    }
  },
  created(){
    this.classMap=['decrease','discount','special','invoice','guarantee'];
    this.$http.get("/api/goods").then((response)=>{
         response=response.body;
         if(response.errno==ERR_OK){
            this.goods=response.data;
            this.$nextTick(()=>{
              debugger
              **console.log(listHeight);**
             this._initScroll();
             this._calculateHeight();
            });

         }
    });
  },
  methods:{
    _initScroll(){
      this.menuScroll=new BScroll(this.$refs.menuWrapper,{});
      this.foodsScroll=new BScroll(this.$refs.foodsWrapper,{
        probeType:3
      });
      this.foodsScroll.on("scroll",(pos)=>{
        this.scrollY=Math.abs(Math.round(pos.y));
      });
    },
    _calculateHeight(){
      let foodList=this.$refs.foodsWrapper.getElementsByClassName("food-list-hook");
      let height=0;
      this.listHeight.push(height);
      for(let i=0;i<foodList.length;i++){
        let item=foodList[i];
        height+=item.clientHeight;
        listHeight.push(height);
      }
    }
  }
}

</script>
这里console.log(listHeight)提示语法错误,listHeight未定义