Skip to content

Message ​

Global message prompt service. Uses a mount-point pattern — the Mini Program cannot create DOM via JS, so the page must first contain the mount-point component.

Place the mount point ​

Place it once on the pages that need message prompts (or in a persistent root wrapper component):

vue
<template>
  <lh-config-provider>
    <view><!-- page content --></view>
    <lh-message />
  </lh-config-provider>
</template>

Usage ​

ts
import { useLhMessage } from '@lh-ui/uniapp'

const message = useLhMessage()

message.success('Saved successfully')
message.info('Info message')
message.warning('Warning message')
message.danger('Error message')
message.error('Error message (alias of danger)')

// A loading prompt that does not auto close (duration: 0), closed manually
const handle = message.loading('Loading...')
// ...after the async work is done
handle.close()

// close all
message.closeAll()

A missing mount point triggers a warning

If you call useLhMessage() but the page has no <lh-message />, a console.error warning is emitted during development and it does not silently degrade. This is intentional: silent degradation would turn "the call seems to work but nothing happens" into a hidden bug.

Methods ​

MethodDescriptionParameters
(direct call)message('xxx') is equivalent to message.info('xxx')(options: LhMessageOptions | string)
success / info / warning / danger / errorShows a message of the corresponding type(content: string, options?: Partial<LhMessageOptions>)
loadingShows a loading prompt that does not auto close (duration: 0); returns a handle for manual closingSame as above
closeCloses the message with the given id(id: number)
closeAllCloses all—

LhMessageOptions ​

PropDescriptionTypeDefault
contentText (required)string—
typeType'success' | 'info' | 'warning' | 'danger' | 'loading''info'
durationDisplay duration (milliseconds); 0 means no auto closenumber3000
showCloseShow the close buttonbooleanfalse
offsetOffset from the top (px)number—
onCloseClose callback() => void—

Global config ​

ts
const message = useLhMessage()
message.config({ duration: 2000, max: 5, offset: 20 })
ConfigDescriptionDefault
durationDefault display duration (milliseconds)3000
maxMaximum number of simultaneous messages—
offsetOffset from the top—

Differences from the Vue3 version

  • No appendTo: the web build mounts to document.body, a concept that does not exist on the Mini Program; the mount position is determined by where <lh-message /> sits in the page.
  • Enter/leave animations use CSS transition + setTimeout to align durations (transitionend is unreliable on the Mini Program).
  • The notification component (Notification) is absent from the first release; use Message as an alternative.