基於 Vue 2.0 實現的移動端彈窗 (Alert, Confirm, Toast)元件.
阿新 • • 發佈:2019-01-30
wc-messagebox
基於 vue 2.0 開發的外掛
包含 Alert, Confirm, Toast, Prompt
仿照 iOS 原生UI(樣式來源: MUI)
一些想法
剛開始的時候想要用現成的彈窗元件來著, 但是查詢一圈沒有發現比較合適專案的, 所以才自己開發了一個, 包含 Alert, Comfirm, Toast, Prompt 四種, 並且可以單個引入.
Vue 的元件開發實際上比較簡單, 有興趣的可以看下原始碼實現, 步驟很清晰.
關於樣式的問題, 是直接從 MUI(魅族開發的) 中拿過來的, 仿照 iOS 的效果.
效果圖
圖是動圖... 動不了點一下就好.
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)