Skip to content

Concepts

In this section, we will dive into the core concepts and features of VueEasyPullRefresh and useEasyPullRefresh. Understanding these concepts will help you use the library more effectively and customize it to fit your needs.

Key Concepts

1. VueEasyPullRefresh Component

VueEasyPullRefresh is the main component that enables the pull-to-refresh functionality. It is designed to wrap the content you want to refresh, and it listens for the user's pull-to-refresh gesture (usually a downward swipe). When the user performs the gesture, the component triggers the refresh process.

How it Works:

  • When the user pulls down the content, the component listens for the touch/mouse events and initiates the refresh process.
  • It emits an event once the refresh action is triggered, allowing you to perform tasks like data fetching or state updates.
  • It can be customized with various props and slots to match the design and functionality of your application.

2. useEasyPullRefresh Function

The useEasyPullRefresh function is a composition API function that allows you to interact with the pull-to-refresh logic inside the setup function. It provides the tools needed to add tasks to the refresh queue and control the refresh behavior programmatically.

How it Works:

  • pullDownQueueAdd: This function is used to add asynchronous tasks (e.g., data fetching, state updates) to the pull-to-refresh queue. These tasks will be executed in order when the pull-to-refresh gesture is performed.
  • refRefresh: This reference allows you to access the VueEasyPullRefresh component directly. It is optional and only required if you need to interact with the component in the same component where it is defined.

3. Queue System

One of the powerful features of useEasyPullRefresh is the ability to queue multiple asynchronous tasks during the pull-to-refresh process. The tasks are executed sequentially, ensuring that the refresh operation does not finish until all tasks have been completed.

How it Works:

  • When the pull-to-refresh gesture is triggered, all tasks in the queue are executed.
  • The queue ensures that tasks are not skipped, and each task will be given time to complete.
  • If a task takes too long, the refresh will keep waiting until the task is either resolved or rejected.

4. Controlled vs. Uncontrolled Refresh

The VueEasyPullRefresh component supports both controlled and uncontrolled behaviors:

  • Uncontrolled: In the default, uncontrolled mode, the component automatically handles the refresh process. The content is re-rendered when the pull-to-refresh action is triggered.
  • Controlled: The component gives you more control over the refresh process. This mode allows you to manually manage when the refresh process ends, providing more flexibility when integrating with asynchronous operations or complex workflows.

Refresh Process Overview

  1. User Interaction: The user performs a pull-to-refresh gesture (usually a downward swipe).
  2. Trigger Refresh: The component detects the gesture and triggers the refresh process.
  3. Task Queue Execution: Any tasks that have been added to the refresh queue using pullDownQueueAdd are executed.
  4. Completion: Once all tasks in the queue are completed, the refresh operation ends, and the content is updated.

Conclusion

The main concepts of VueEasyPullRefresh revolve around simplifying the implementation of pull-to-refresh functionality and allowing flexibility in how refresh tasks are managed. Whether you're using the default uncontrolled behavior or the more flexible controlled mode, the library provides a seamless solution for adding pull-to-refresh to your Vue application.

By understanding the core concepts, you can easily integrate and customize the pull-to-refresh experience in your project.