javascript - export default中的data选项设置了值,但是获取不到
PHP中文网
PHP中文网 2017-04-11 11:04:52
[JavaScript讨论组]

<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 去哪了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号