Giter Club home page Giter Club logo

vue-mugen-scroll's Introduction

vue-mugen-scroll NPM version NPM downloads Build Status

むげん [mugen] means Infinity in English.

Features

  • Small, only weighs 2kb
  • Insanely easy to use, it's just a component with a couple props

Install

$ npm install --save vue-mugen-scroll

CDN: https://unpkg.com/vue-mugen-scroll/dist/

Demo: JSFiddle

Usage

<template>
  <div id="app">
    <div class="list">your list of items</div>
    <!-- add the component right after your list -->
    <mugen-scroll :handler="fetchData" :should-handle="!loading">
      loading...
    </mugen-scroll>
  </div>
</template>

<script>
  import MugenScroll from 'vue-mugen-scroll'
  export default {
    data() {
      // do not run handler when it's loading
      return {loading: false}
    },
    methods: {
      fetchData() {
        this.loading = true
        // ... the code you wanna run to fetch data
        this.loading = false
      }
    },
    components: {MugenScroll}
  }
</script>

API

props

handler

Type: function
Required: true

The handler function to run after you scroll to the bottom of the list. It will also be invoked on component mounted and the mugen-scroll component is visible in viewport.

handleOnMount

Type: boolean
Default: true

Invoke the handler function on component mounted.

shouldHandle

Type: boolean
Default: true

Add an additional condition to check if it should invoke the handler function, for example you don't want it to be invoked again as it's loading.

threshold

Type: number
Default: 0

Set the ratio of the <mugen-scroll>'s height and width that needs to be visible for it to be considered in viewport. This defaults to 0, meaning any amount. A threshold of 0.5 or 1 will require that half or all, respectively, of the element's height and width need to be visible. threshold must be a number between 0 and 1

scrollContainer

Type: string

If the container of your list is scrollable, you can specific the reference ID of the container, so that we can detect the scroll event of this element instead of window.

<template>
  <div class="wrap"
    <!-- the container is scrollable here -->
    style="height: 200px; overflow: auto;"
    <!-- add the ref -->
    ref="wrap">
    <div class="list"><!-- your list --></div>
    <mugen-scroll
      <!-- pass the ref id -->
      scroll-container="wrap">
      Loading...
    </mugen-scroll>
  </div>
</template>

Development

You can run the example with vbuild

git clone https://github.com/egoist/vue-mugen-scroll.git
cd vue-mugen-scroll
yarn
yarn example

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT © EGOIST

vue-mugen-scroll's People

Contributors

chatoo2412 avatar egoist avatar jericopulvera avatar rezahaidari avatar rfp avatar whxaxes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-mugen-scroll's Issues

How do you use this without common?

I am using this just on one page so not using a component, and I am new to Vue.js. In my page (I am using laravel, I have this for my list:

<ul class="styled-list">

      <li class="list-head">
        <div>Name</div>
        <div>Month</div>
        <div>Year</div>
      </li>

      <li class="list-body" v-for="account in accounts">
        <div>@{{ account.name }}</div>
        <div v-bind:class="account.month_class" >@{{ account.month_diff }}%</div>
        <div v-bind:class="account.year_class" >@{{ account.year_diff }}%</div>
      </li>

      <mugen-scroll :handler="fetchData" :should-handle="!loading">
        loading...
      </mugen-scroll>

    </ul>

then in my footer:

<script src="https://unpkg.com/[email protected]/dist/vue-mugen-scroll.min.js"></script>

  <script type="text/javascript">

      var vm = new Vue({
          el: '.table-wrap',
          data: {
              accounts: [],
              moreAccounts: [],
              loading: false
          },
          mounted:  function() {

            var dist = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);

            this.$http.get( '/api/accountsByDistributor?dist='+dist+'&order=desc&order_by=current_year&limit=10' ).then(function (response){

                vm.accounts = response.body;
               
            }, function (response){
                  console.log(response);
            });

            this.$http.get( '/api/accountsByDistributor?dist='+dist+'&order=desc&order_by=current_year&limit=-1' ).then(function (response){

                vm.moreAccounts = response.body;
               
            }, function (response){
                  console.log(response);
            });

          },
          methods: {
            fetchData: function() {

              this.loading = true;

              console.log(this.moreAccounts.length);

              if(this.moreAccounts.length > 0)
              {
                setTimeout(function () 
                {
                    var temp = [];
                    for (var i = this.moreAccounts.length; i <= this.moreAccounts.length + 10; i++) {
                        temp.push( this.moreAccounts[i] );
                    }

                    this.accounts = this.accounts.concat(temp);
                    
                }.bind(this), 1000);

                this.loading = false;
              }
              
            }
          },
          components: {
            MugenScroll
          }
      });

  </script>

Yet it is not working.

How to handle scrollContainer with nested lists?

I am having a nested list and my inner list needs to have infinite scroll. This scrollContainer attributes just seem right to me, but I am facing a problem that I cannot name the ref dynamically. And in the documentation, it says the refs will be an array under v-for. In that case, how should I go about using this attribute?

load overflow scroll issue

I have a problem with infinite-scroll in "overflow:scroll" section, when i scroll this section to end, just loading will appear but doesn't handle method until page(browser) scrolled.

issue

If fires the handler even when the page is not active

Hi,
Thanks for the package, but there is a problem the handler keeps firing even when the page is no active.

I have a single page app using vue router.
I'm using you package in the grid component to load more rows when the user reach the bottom of the page.
A user can click on more details to open the details page of a row.

I'm using <keep-alive include="papers-grid"></keep-alive> on the grid component only.

So when the details pages is opened, vue will keep the grid component alive but inative.

In this case when i scroll in the details page the mugen scroll handler keep firing non stop on each scroll event


EDIT: For now what i'm doing is that i'm tracking if the grid page is active using the route guards, and using that in he :should-handle.
But i guess that the behaviour of firing the handler only when the page is active should be handeled by the mugen package if that is possible

Threshold parameter not working?

Thanks for the great work on this useful component!

The JSFiddle demo doesn't demonstrate use of the threshold prop, so I have created one here (which also fixes what I think is a bug in the numbering of the card titles).

It seems to work, with the threshold set to 0.5, but changing it to 0.7 causes the list to no longer grow. Perhaps I'm using it wrong, in which case it would be nice to have the correct use shown in the demo.

While trying to understand how it was supposed to work, I looked at the code in your master branch, and compared it to the code in the npm package. This lead to some confusion, as it seems there are fixes in master that haven't been included in the npm package, even though the package.json in master still lists a version number of 0.2.5.

To improve this situation, please consider at least bumping the version in the package.json (if necessary to something like 0.2.6-pre1) and ideally please release an updated 0.2.6 npm package that includes a fix for the threshold issue (if it really is an issue).

More generally, you might be interested in the discussion about verifying npm packages against their source repos. I tried checking the status of the package against an online verifier and it reported unverified, but that might not be relevant or accurate.

Hide loader when shouldHandle is false

Super useful component, thanks you! I think the loader should be hidden when shouldHandle is false, is it possible?

It would be useful when you reach the end of the results. I've used a simple v-show directive for now

Not found response for first load page

Hi,

I have some problem with vue-mugen-scroll, this is my code

import Imagecategory from './Imagecategory'
import MugenScroll from 'vue-mugen-scroll'

export default {
  data() {
    return {
      images: [],
      paginate: [{
        prev: ''
      }, {
        next: ''
      }],
      loading: false
    }
  },
  methods: {
    getPage(code) {
      this.$http({
        url: 'http://open.lovebizhi.com/bdrom/category?code=' + this.$route.params.code,
        method: 'get'
      }).then(response => {
        this.images = response.body.data
        this.paginate = response.body.link
      });
    },
    fetchData() {
      this.loading = true
      this.$http({
        url: this.paginate.next,
        method: 'get'
      }).then(response => {
        this.images = [...this.images, ...response.body.data]
        this.paginate = response.body.link
      });
      this.loading = false
    }
  },
  watch: {
    '$route.params.code' (n, o) {
      this.getPage()
    }
  },
  created() {
      this.getPage()
  },
  components: {
    Imagecategory,
    MugenScroll
  }
}

At first loading, this code will show not found error
screenshot_1

How to fix this problem?

Thanks

Recheck if data still needs to be loaded?

Hi,

I have this case that after fetchData there is still white space that mugen could still fill in with data, but he don't want to becasue there is no scroll yet. In smaller resolution it's working fine (scroll is there from very beggining) but in higher resolution it's stops to work. I have tried to experiment with couple combinations of params but no effects. I know that one solution would be to take bigger chunk of data, but still you will be able to find screen resolution that this chunk of data is unsufficient to fill whole white space.

Any ideas? Thanks!

P.S.
Great plugin mate!

After handler had completed - mugen-component stays in viewport...

and stop firing handler at all, reacting only on scroll and resize events.

My case.

I get 20 chat messages from server for initial. If it takes more space than viewport offer - it's ok, coz I need to scroll.

But if mugen-compo stays in viewport - nothing happens. It's strange behaviour. The only chance to fire event - resizing browser.

Now I add 'DOMNodeInserted' to triggers array and it work.

请教外层的wrap必须要设置高度吗

<script> import is from 'is' import util from 'util' import MugenScroll from 'vue-mugen-scroll' export default { name: 'app', data() { return { recentitems: [], count: 1, loading: false } }, methods: { getHumanDate : function (date) { return moment(date).format("YYYY-MM-DD") }, async fetchUsers() { this.loading = true util.get(`News/recentimgnews?page=`+this.count+`&time=`, {}, ({data}) => { if(data.length>0) { data.forEach((item) => this.recentitems.push(item)) } }) this.count++ this.loading = false } }, components: { MugenScroll } } </script>

这里有两个问题:
1)外层的wrap必须要设置高度吗
2)数据加载完成之后,下拉然后在上拉,又会触发事件,请问怎样才可以停止

Not working well with Quasar layouts?

I'm trying to use this component with Quasar layouts.
Minimal example:

<template>
  <q-layout>
    <div class="layout-view">
        <mugen-scroll :handler="fetchData">
          loading...
        </mugen-scroll>
    </div>
  </q-layout>
</template>

Results in this error:

[Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'addEventListener' of undefined"

found in

---> <MugenScroll>
       <QLayout>
         <Index> at /Users/pignatelli/src/test/infinite-test/src/components/Index.vue
           <App> at /Users/pignatelli/src/test/infinite-test/src/App.vue
             <Root>

Commenting out <q-layout></q-layout> eliminates the error.
Any idea how to fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.