GithubHelp home page GithubHelp logo

moment3784 / wc-messagebox Goto Github PK

View Code? Open in Web Editor NEW

This project forked from helicopters/wc-messagebox

0.0 1.0 0.0 559 KB

基于 Vue 2.0 开发的 Alert, Toast, Confirm 插件, UI仿照 iOS 原生

JavaScript 54.15% HTML 2.32% Vue 32.24% CSS 11.29%

wc-messagebox's Introduction

wc-messagebox

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

效果

效果

Install

npm i wc-messagebox --save

Quick Start

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

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

Usage

// alert
this.$alert(text, options)
options = {
	title: '',  // 默认标题为 '提示'
	btn: {
		text: '',
		style: {} // 可以通过 style 来修改按钮的样式, 比如说粗细, 颜色
	}
}

// confirm
this.$confirm(content, options)
options = {
    title: '', 
    yes: {
        text: '确定',
        style: {}
    },
    no: {
        text: '取消',
        style: {}
    }
}

// toast
this.$toast(content, duration);

// prompt
this.$prompt(content, options)
options = {
    title: '',
    placeholder: '', 
    yes: {
        text: '确定',
        style: {}
    },
    no: {
        text: '取消',
        style: {}
    }
}

Introduction

  • Alert, Confirm 返回的是一个Promise, 允许定义点击弹窗之后的操作
this.$confirm(text)
    .then(success)
    .catch(fail)
  • 关于是否应该提供三个版本, 微信, 安卓, iOS 三种样式. 为什么会有这样的想法, 因为我的确是觉得,在安卓设备里面你弹出来一个和 iOS 一样的 弹窗, 有一点违和的感觉 这种违和的感觉, 让我非常不爽, 所以我才想要去提供. 但是顾虑是:
    1. 提供了之后会增加文件的大小, 包括 js 和 css
    2. 提供了之后, 会不会适得其反, 比如说实际上用户只是想要 iOS 弹窗的效果, 对其他的方式一点 都不考虑呢
    3. 有没有让事情变的复杂起来了, 一个简单的弹窗, 为什么还需要做这么复杂?如果你提供的三种样式都不喜欢, 用户是不是还可以自己定制呢?用户如果自己定 制, 你是不是还需要定义额外的事情呢.
    4. 那么推广, 是不是所有你所定义的组件, 都需要给定几套不一样的样式来兼容不同的组件呢 而且这样的情况是不是符合项目的要求呢, 你这样做完之后, 是不是一点意义都没有呢

如何基于本项目定制化开发

有时候你可能需要弹窗的样式变成和你项目所相符合的, 但是又不想要自己写弹窗的逻辑. 可以基于本项目进行二次开发. 具体的步骤如下:

  1. clone 本项目
  2. npm install 安装依赖
  3. html 不建议修改, 但是样式可以改成你所需要的, 弹窗的所有样式都在 src/wc-messagebox/css/style.css 中
  4. npm run dev 可以在本地查看修改效果.

wc-messagebox's People

Contributors

helicopters avatar

Watchers

James Cloos avatar

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.