|
| 1 | +--- |
| 2 | +sidebar: auto |
| 3 | +--- |
| 4 | + |
| 5 | +# API |
| 6 | + |
| 7 | +## Props |
| 8 | + |
| 9 | +The default value for these properties can be overridden through the Plugin API. |
| 10 | + |
| 11 | +### distance |
| 12 | + |
| 13 | +- Type: `Number` |
| 14 | +- Default: `100` |
| 15 | +- Details: |
| 16 | + |
| 17 | +The `infinite` event will be fired if the scroll distance is less than this value. If `direction` is set to `top`, it will calculate the distance between the scroll bar and the top, if `direction` is set to `bottom`, it will calculate the distance between the scroll bar and the bottom. |
| 18 | + |
| 19 | +### spinner |
| 20 | + |
| 21 | +- Type: `String` |
| 22 | +- Default: `default` |
| 23 | +- Available: `default` | `spiral` | `circles` | `bubbles` | `waveDots` |
| 24 | +- Details: |
| 25 | + |
| 26 | +This property is used to set the loading animation, you can choose one from the internal spinners that you like, you can also customize it with a [named slot](https://vuejs.org/v2/guide/components.html#Named-Slots) that called `spinner`. |
| 27 | + |
| 28 | +### direction |
| 29 | + |
| 30 | +- Type: `String` |
| 31 | +- Default: `bottom` |
| 32 | +- Available: `top` | `bottom` |
| 33 | +- Details: |
| 34 | + |
| 35 | +This property is used to set the load direction. |
| 36 | + |
| 37 | +### forceUseInfiniteWrapper |
| 38 | + |
| 39 | +- Type: `Boolean` | `String` |
| 40 | +- Default: `false` |
| 41 | +- Details: |
| 42 | + |
| 43 | +By default, the component will search for the closest parent element which has `overflow-y: auto | scroll` CSS style as the scroll container, this property is used to force to specify the scroll container, usually used when the case has complex layout or 3rd-party scroll plugin (eg: [`perfect-scrollbar`](https://github.com/noraesae/perfect-scrollbar)). |
| 44 | + |
| 45 | +If this value set be `true`, the component will search the closest parent element which has `infinite-wrapper` attribute as the scroll container, if this value is a string, the component will use it as a CSS selector, and search the element as the scroll container via the `querySelector` API, if all failed, the component will use `window` as the scroll container. |
| 46 | + |
| 47 | +### identifier |
| 48 | + |
| 49 | +- Type: `any` |
| 50 | +- Default: `+new Date()` |
| 51 | +- Details: |
| 52 | + |
| 53 | +The comopnent will be reset if this property has changed, just like recreating a new comopnent, usually used when the case has filter or tabs. |
| 54 | + |
| 55 | +## Slots |
| 56 | + |
| 57 | +The contents for these slots can be configured via the [`slot` special attribute](https://vuejs.org/v2/api/index.html#slot), also can be configure via the plugin API. |
| 58 | + |
| 59 | +### no-results |
| 60 | + |
| 61 | +- Default: `No results :(` |
| 62 | +- Details: |
| 63 | + |
| 64 | +This message will be displayed if there is no data, it means we did not call the `$state.loaded` method before calling the `$stat.complete` method. |
| 65 | + |
| 66 | +### no-more |
| 67 | + |
| 68 | +- Default: `No more data :)` |
| 69 | +- Details: |
| 70 | + |
| 71 | +This message will be displayed if there is no more data, it means we called the `$state.loaded` method before calling the `$state.complete` method. |
| 72 | + |
| 73 | +### error |
| 74 | + |
| 75 | +- Default: `Opps, something went wrong :(` |
| 76 | +- Details: |
| 77 | + |
| 78 | +This message will be displayed if loading failed, it means we called the `$state.error` method. |
| 79 | + |
| 80 | +Unlike other slots, the default value for this slot will provide a retry button for users to load data again. If you want to impletement a retry button for users when you customize this slot, you can use the [`slot-scope`](https://vuejs.org/v2/api/index.html#slot-scope) feature, like this: |
| 81 | + |
| 82 | +``` html |
| 83 | +<infinite-loading @infinite="infiniteHandler"> |
| 84 | + <div slot="error" slot-scope="{ trigger }"> |
| 85 | + Network error, click <a href="javascript:;" @click="trigger">here</a> to retry |
| 86 | + </div> |
| 87 | +</infinite-loading> |
| 88 | +``` |
| 89 | + |
| 90 | +## Events |
| 91 | + |
| 92 | +### infinite |
| 93 | + |
| 94 | +- Argument: `event` |
| 95 | +- Details: |
| 96 | + |
| 97 | +This event will be fired if the scroll distance is less than the `distance` property, the component will pass a special event argument for the event handler to change loading status, usually we name it `$state`, include these methods: |
| 98 | + |
| 99 | +#### $state.loaded |
| 100 | + |
| 101 | +Inform the component that this loading has been successful, and the `infinite` event will be fired again if the first screen was not be filled up, otherwise, the component will hide the loading animation and continue to listen scroll event. |
| 102 | + |
| 103 | +#### $state.complete |
| 104 | + |
| 105 | +Inform the component that all the data has been loaded successfully, if the `$state.loaded` method has not been called before this, the content of `no-results` slot will be displayed, otherwise, the content of `no-more` slot will be displayed. |
| 106 | + |
| 107 | +#### $state.error |
| 108 | + |
| 109 | +Inform the comopnent that this loading failed, the content of `error` slot will be diplayed. |
| 110 | + |
| 111 | +#### $state.reset |
| 112 | + |
| 113 | +Reset the component, same as changing the `identifier` property. |
0 commit comments