javascript - export default中的data选项设置了值,但是获取不到
PHP中文网
PHP中文网 2017-04-11 11:04:52
0
1
1967

<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未定义

PHP中文网
PHP中文网

认证0级讲师

全部回复(1)
大家讲道理

this 去哪了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板