my.showLoading displays a loading indicator dialog, typically used during asynchronous operations. my.hideLoading dismisses the loading dialog when the operation completes.
my.showLoading with my.hideLoading to ensure the loading indicator is properly dismissed. The loading dialog blocks user interaction until it's hidden.Show the loading dialog.
my.showLoading({
content: 'loading...',
delay: 1000,
});
| Property | Type | Required | Description |
|---|---|---|---|
content | String | No | Text contents of loading. |
delay | Number | No | Displaying delay, in ms, 0 by default. If my.hideLoading was called before this time, it is not displayed. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
Hide the loading dialog.
my.hideLoading();
Example with page context:
// Show loading on page load
window.onload = function() {
my.showLoading();
setTimeout(() => {
my.hideLoading({
page: this, // Prevents switching to other pages when execution
});
}, 4000);
}
| Property | Type | Required | Description |
|---|---|---|---|
page | Object | No | Specifically it means the current page instance. In some scenarios, it is required to specify the exact page for hideLoading. |
delay is set and my.hideLoading is called before the delay expires, the loading indicator will not be displayed at allpage parameter in my.hideLoading when you need to ensure the loading is dismissed on a specific page instancemy.hideLoading() after my.showLoading() to avoid blocking the UI indefinitely// Show loading
my.showLoading({
content: 'Processing...',
});
// Perform async operation
setTimeout(() => {
// Hide loading when done
my.hideLoading();
my.alert({
title: 'Complete',
content: 'Operation finished successfully',
});
}, 2000);
my.showLoading({
content: 'Loading data...',
delay: 500, // Only show if operation takes longer than 500ms
});
// Fetch data
fetchData().then(() => {
my.hideLoading();
});
// Show loading on page load
window.onload = function() {
my.showLoading({
content: 'Loading...',
});
// Simulate async operation
setTimeout(() => {
my.hideLoading({
page: this, // Ensures hideLoading targets correct page instance
});
}, 3000);
}
function loadData() {
my.showLoading({
content: 'Loading data...',
});
fetch('/api/data')
.then(response => response.json())
.then(data => {
// Update your UI with data
updateUI(data);
my.hideLoading();
})
.catch(error => {
my.hideLoading();
my.alert({
title: 'Error',
content: 'Failed to load data',
});
});
}