温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

详解基于Vue2.0实现的移动端弹窗(Alert, Confirm, Toast)组件

发布时间:2020-10-24 11:46:06 来源:脚本之家 阅读:349 作者:云水摇啊摇 栏目:web开发

wc-messagebox

  1. 基于 vue 2.0 开发的插件
  2. 包含 Alert, Confirm, Toast, Prompt
  3. 仿照 iOS 原生UI(样式来源: MUI)

一些想法

刚开始的时候想要用现成的弹窗组件来着, 但是查找一圈没有发现比较合适项目的, 所以才自己开发了一个, 包含 Alert, Comfirm, Toast, Prompt 四种, 并且可以单个引入.

Vue 的组件开发实际上比较简单, 有兴趣的可以看下源码实现, 步骤很清晰.

关于样式的问题, 是直接从 MUI(魅族开发的) 中拿过来的, 仿照 iOS 的效果.

效果图

详解基于Vue2.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)

项目地址

项目地址

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI