JSFiddle - React, Tailwind, and code Playground

by leopoldthecuber

HTML

<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui/lib/index.js"></script>
<div id="app">
<template>
  <el-button @click="open1">成功</el-button>
  <el-button @click="open2">警告</el-button>
  <el-button @click="open3">消息</el-button>
  <el-button @click="open4">错误</el-button>
</template>
</div>

SCSS

@import url("//unpkg.com/element-ui/lib/theme-chalk/index.css");

Babel + JSX

var Main = {
  created() {
    let instance;
    const pool = [];
    this.myMessage = (options) => {
      if (instance) {
        pool.push(options);
      } else {
        instance = this.$message(Object.assign({
          onClose: () => {
            instance  = null;
            if (pool.length) {
              this.myMessage(pool.shift());
            }
          }
        }, options));
      }

    }
  },
  methods: {
    open1() {
      this.myMessage({
        message: '恭喜你,这是一条成功消息',
        type: 'success'
      });
    },

    open2() {
      this.myMessage({
        message: '警告哦,这是一条警告消息',
        type: 'warning'
      });
    },

    open3() {
      this.myMessage({
        message: '这是一条消息提示'
      });
    },

    open4() {
      this.myMessage({
        message: '错了哦,这是一条错误消息',
        type: 'error'
      });
    }
  }
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')