UI APIs

alert

Display a simple alert dialog with a title, content, and single button.

Overview

my.alert displays an alert box with customizable title, content, and button text. This is a modal dialog that requires user interaction to dismiss.

Sample Code

my.alert({
  title: 'Tips',
  content: 'Your bill for this month has been released',
  buttonText: 'Show',
  success: () => {
    my.alert({
      title: 'Click "Show"',
    });
  },
});

Parameters

PropertyTypeRequiredDescription
titleStringNoTitle of the alert box.
contentStringNoContents of the alert box.
buttonTextStringNoButton text, which is OK by default.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

Usage Notes

  • The alert is a modal dialog - it blocks interaction with the rest of the Mini Program until dismissed
  • Default button text is "OK" if buttonText is not specified
  • Only one button is displayed (use my.confirm for two-button dialogs)
  • The success callback is triggered when the user taps the button

Examples

Basic Alert

my.alert({
  title: 'Payment Successful',
  content: 'Your order has been processed',
});

Alert with Custom Button

my.alert({
  title: 'Notification',
  content: 'You have a new message',
  buttonText: 'View',
  success: () => {
    console.log('User clicked View');
  },
});