基于 Vue 2.0 完成的挪动端弹窗 (Alert, Confirm, Toast)组件.

wc-messagebox

  • 基于 vue 2.0 开辟的插件

  • 包括 Alert, Confirm, Toast, Prompt

  • 模仿 iOS 原生UI(款式泉源: MUI)

一些主意

刚开始的时刻想要用现成的弹窗组件来着, 然则查找一圈没有发明比较适宜项目的, 所以才本身开辟了一个, 包括 Alert, Comfirm, Toast, Prompt 四种, 而且能够单个引入.
Vue 的组件开辟实际上比较简单, 有兴致的能够看下源码完成, 步骤很清楚.
关于款式的题目, 是直接从 MUI(魅族开辟的) 中拿过来的, 模仿 iOS 的结果.

结果图

《基于 Vue 2.0 完成的挪动端弹窗 (Alert, Confirm, Toast)组件.》
图是动图… 动不了点一下就好.

Install

npm i wc-messagebox --save

Quick Start

import {Alert, Confirm, Toast} from 'wc-messagebox'
import 'wc-messagebox/style.css'

Vue.use(Alert, options)
Vue.use(Confirm, options)
Vue.use(Toast, options)

Usage

this.$alert(text, options)
options = {
    title: '',  // 默许无标题
    btn: {
        text: '',
        style: {
            'backgroun-color': 'red',
            'font-size': '20px',
            'color': 'blue'
        }
    }
}

this.$confirm(text, options)
options = {
    title: '', // 默许无标题
    yes: {
        text: '肯定',
        style: {}
    },
    no: {
        text: '作废',
        style: {}
    }
}
this.$toast(text, options);
options = {
    position: 'bottom' // 'bottom' | 'center',
    duration: '1500'
}

其他

Alert, Confirm 返回的是一个Promise, 以支撑链式挪用.

this.$confirm(text).then(success).catch(fail)

项目地点

项目地点

    原文作者:云水摇啊摇
    原文地址: https://segmentfault.com/a/1190000009705021
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞