Code Monkey home page Code Monkey logo

m-message's Introduction

vue-m-message

A message plugin base on Vue.

v4.x version only supports Vue 3; If you use Vue 2, use v3.x instead.

Preview

中文 | Live Demo

npm install vue-m-message

# Vue 2
# npm install vue-m-message@3
import { createApp, h } from 'vue'
import Message from 'vue-m-message'
import 'vue-m-message/dist/style.css'
import App from './App.vue'

const app = createApp(App)

app.use(Message)
// or
app.use(Message, options: { name?: string, defaultOptions?: MessageTypeOptions })

// Message.info('Wellcome here !', { duration: -1, ctx: instance?.appContext })
// Message.info(h('m-demo', 'Wellcome here !'), { duration: -1 })
Message.info(() => h('div', [
  'Here is playground for ',
  h('a', { href: 'https://github.com/mengdu/m-message' },'Vue Message'),
  ' plugin.'
]), {
  title: 'Wellcome here !',
  duration: -1,
  iconURL: 'https://avatars.githubusercontent.com/u/11366654?s=40&v=4'
})
// Message.info(<m-demo>Wellcome here !</m-demo>, { duration: -1 })
// Message.info(() => <m-demo>Wellcome here !</m-demo>, { duration: -1 })

app.mount('#app')

Message API

  • Message(options: MessageOptions): MessageIntance General prompt information
  • Message.info(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Info prompt information
  • Message.success(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Success prompt information
  • Message.error(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Error prompt information
  • Message.warning(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Warning prompt information
  • Message.loading(message: string | VNode | (() => VNode), options?: MessageTypeOptions): MessageIntance Loading prompt information
  • Message.closeAll(): void Clear all prompts
  • Message.setDefault(options: MessageTypeOptions): void Set default values
type MessageTypeOptions = Omit<MessageOptions, 'type' | 'message'>

interface MessageIntance {
  id: string
  close: () => void
}

MessageOptions

Attribute Description Type Optional value Default
type Message type icon string '', 'info', 'success', 'error', 'warning', 'loading' 'info'
iconURL Replace type icon with picture string
title Message title string ''
message Message content string ''
position Message display position string 'top-left', 'top-center', 'top-right', 'center', 'bottom-left', 'bottom-center', 'bottom-right'
duration Message display duration, in MS; When ` - 1 ', it needs to be closed manually number 3000
width Message block width, auto width by default string ''
className class name string
wrapperClassName class name for wrapper string
zIndex z-index number 1010
supportHTML Whether the message content supports HTML (only valid when the message is a string) boolean true/false false
isCollapsed Collapse content boolean true/false false
collapsable Collapsable boolean true/false false
closable Whether it can be closed boolean true/false false
hasMask Does it contain a mask boolean true/false false
stopTimerOnHover Whether to recalculate the display duration when the mouse moves over boolean true/false true
onClose Close callback () => void
onCollapsed Fold switch callback (collapsed: boolean) => void

License

Licensed as MIT.

m-message's People

Contributors

jiazehua avatar mengdu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

m-message's Issues

There are multiple modules with names that only differ in casing.

I really commend the great work done with this plugin.

Please i got an error on the console while running npm run dev

There are multiple modules with names that only differ in casing.                            friendly-errors 22:21:09
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Use equal casing. Compare these module identifiers:
* /Library/WebServer/Documents/ngcareers/node_modules/Vue/dist/vue.runtime.esm.js
    Used by 1 module(s), i. e.
    /Library/WebServer/Documents/ngcareers/node_modules/vue-m-message/dist/index.js

I guess the fix is by changing require("Vue") to require("vue") and define("Message",["Vue"],e) to define("Message",["vue"],e)

Please can you kindly help look into this.

Thank you.

Disable folding option

Hi can you add an option to disable message folding entirely? something like

{ collapsable: false }

支持vue3吗

Unexpected error when starting the router: TypeError: Cannot read property 'extend' of undefined

Null Point

错误消息

TypeError: Cannot read property 'remove' of null

错误产生的地方

if (hasMask && index === -1) {
          setTimeout(function () {
            containers[containerKey].remove();
            containers[containerKey] = null;
          }, 300);
}

复现

不断的操作弹框,消失又打开不断反复

support: update message content with key or reactive

<template>
  <a-button type="primary" @click="openMessage">Open the message box (update by key)</a-button>
  <br />
  <br />
  <a-button type="primary" @click="openMessage2">
    Open the message box (update by reactive)
  </a-button>
</template>
<script lang="ts">
import { message } from 'ant-design-vue';
import { defineComponent, ref } from 'vue';
const key = 'updatable';
export default defineComponent({
  setup() {
    const openMessage = () => {
      message.loading({ content: 'Loading...', key });
      setTimeout(() => {
        message.success({ content: 'Loaded!', key, duration: 2 });
      }, 1000);
    };
    const content = ref('Loading...');
    const openMessage2 = () => {
      // content must use function
      message.loading({ content: () => content.value });
      setTimeout(() => {
        content.value = 'Loaded!';
      }, 1000);
    };
    return {
      openMessage,
      openMessage2,
    };
  },
});
</script>

ref: https://codesandbox.io/s/gmc46q?file=/src/demo.vue:745-752 (ant-design-vue: message)

HTML in message

If I wanted to pass in a message with some HTML, for example, an anchor tag, how would I do that? If I pass just a string, obviously it gets escaped and the HTML shows up in the toast.

Example: I would like to be able to do this:

this.$message.error({
  message: `Oops. Please contact <a href="mailto:[email protected]">[email protected]</a>`
})

CDN Global

please, Can you give an example with CDN?

I am using:

Vue.use(window.VueMMessage);

handleMessage: function() {
        this.$message({
            type: "info",
            message: "this is a test",
            showClose: true,
            position: "top-center",
            hasMask: false,
        })
    },

And I get this error:

[Vue warn]: Error in v-on handler: "TypeError: this.message is not a function"

(found in )
warn @ vue.js:634
logError @ vue.js:1902
globalHandleError @ vue.js:1897
handleError @ vue.js:1857
invokeWithErrorHandling @ vue.js:1880
invoker @ vue.js:2197
original._wrapper @ vue.js:7591
vue.js:1906 TypeError: this.message is not a function
at Vue.handleMessage (index.html:130:14)
at click (eval at createFunction (vue.js:11698:14), :3:603)
at invokeWithErrorHandling (vue.js:1872:28)
at HTMLButtonElement.invoker (vue.js:2197:16)
at HTMLButtonElement.original._wrapper (vue.js:7591:27)

Thank you

Global settings?

Hello,

First of all, thanks for that beautiful plugin.

Can we have a global settings object? Like when we write:

Message.globals.config.position = 'bottom-right';

All the calls to Message.{type} would use bottom-right positioning.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.