new Vue({
  el: '#app',
  data: function data() {
    return {
      bottom: false,
      beers: []
    };
  },

  watch: {
    bottom: function bottom(_bottom) {
      if (_bottom) {
        this.addBeer();
      }
    }
  },
  created: function created() {
    var _this = this;

    window.addEventListener('scroll', function () {
      _this.bottom = _this.bottomVisible();
    });
    this.addBeer();
  },

  methods: {
    bottomVisible: function bottomVisible() {
      var scrollY = window.scrollY;
      var visible = document.documentElement.clientHeight;
      var pageHeight = document.documentElement.scrollHeight;
      var bottomOfPage = visible + scrollY >= pageHeight;
      return bottomOfPage || pageHeight < visible;
    },
    addBeer: function addBeer() {
      var _this2 = this;

      axios.get('https://api.punkapi.com/v2/beers/random').then(function (response) {
        var api = response.data[0];
        var apiInfo = {
          name: api.name,
          desc: api.description,
          img: api.image_url,
          tips: api.brewers_tips,
          tagline: api.tagline,
          food: api.food_pairing
        };
        _this2.beers.push(apiInfo);
        if (_this2.bottomVisible()) {
          _this2.addBeer();
        }
      });
    }
  }
});

  

最新文章

  1. Git常用命令速查表
  2. django之form表单验证
  3. iOS边练边学--父子控件之作为导航控制器的子类产生的问题以及网易新闻练习
  4. Duilib中Webbrowser事件完善使其支持判断页面加载完毕
  5. [maven] 跳过单元测试
  6. Python argparse
  7. python 判断 windows 隐藏文件/系统文件
  8. Mysql 8个小时连接断开问题解析
  9. mvc wcf 并发提示,存储Application,验证是否有用户在操作
  10. [LA] 2031 Dance Dance Revolution
  11. 前端开发:H5直播起航
  12. 用html和css轻松实现康奈尔笔记(5R笔记)模板
  13. 开源库Magicodes.Storage正式发布
  14. 预计2019年发布的Vue3.0到底有什么不一样的地方?
  15. myBatis简学
  16. vue---computed计算属性的使用
  17. AndroidStudio环境安装与配置
  18. python之模块配置文件ConfigParser(在python3中变化较大)
  19. Windows系统32位、64位DLL文件的存放位置
  20. WP 8.1 status bar

热门文章

  1. JavaWeb错误处理集锦
  2. 关于webuploader跨域解决方法
  3. JavaScript学习——表格的隔行换色+高亮显示
  4. iOS Device Types
  5. 8年js总结
  6. DotNetCore.1.0.1-VS2015Tools.Preview2.0.3 相关问题及解决办法
  7. vmware workstation中的NAT配置
  8. 优动漫PAINT-凌霄花画法
  9. for 的相关用法
  10. php对excel导入导出的支持