1.0.3 • Published 6 years ago

vue-kdialog v1.0.3

Weekly downloads
75
License
MIT
Repository
github
Last release
6 years ago

vue-kdialog

A Vue dialog component 基于 vue 2.x 版本的弹窗组件

npm.io

Usage (使用)

1, import kdialog component (导入 kdialog 组件);

2, vue.use(kdialog) (调用vue.use(kdialog)方法);

3, congratulations! (好了,可以尽情使用了!)

import Vue from 'vue';
import kdialog from 'vue-kdialog';

Vue.use(kdialog);

Suport (功能)

There are many types u can use (内置了多种功能供你使用):

1, $loading, need to close manually (需要手动调用关闭方法,否则不会消失):

const loading = this.$loading();
// close it when u need:
loading.close();

2, $toast, it will disappear after default 2500ms, change it like this (无需手动调用关闭方法,在参数timer时间后自动消失,默认为2500ms):

this.$toast({
	msg: 'This is a test for toast',
	timer: 3000
});

3, $alert, there is only one button (只有1个确定按钮):

this.$alert({
	width: 300,
	title:'Alert',
	content:'<p style="text-align:center">This is a test for Alert</p>',
	okText:'Yes'
});

4, $confirm, there a 2 buttons (有2个按钮):

this.$confirm({
	width: 500,
	content:'<p style="text-align:center">This is a test for Alert</p>',
	okText:'Yes'
});

5, component, 自定义组件

import a from 'a'
this.$confirm({
	width: 500,
	component: a,
	ok(kdialog){
		kdialog.disabled = true;
	},
	cancel(kdialog){
		kdialog.close();
	}
});

参数列表:

paramstypedescription (参数解释)
bodyreserved words(不要覆盖)control the position of the dialog (弹窗唤起位置class)
rollfromString ('center'/'top'/'bottom' default : 'center')control the position of the dialog (弹窗唤起位置class)
titleStringtitle of dialog (弹窗标题)
showBoolenshow or remove the dialog dom (显示或移除弹窗dom节点)
customClassStringcustom className for dialog (弹窗自定义className)
_typereserved words(不要覆盖)don't override it (内部组件使用,请勿覆盖)
_runtimereserved words (default : 'pc' 不要覆盖)kdialog.setRunTime('m'); (用于判断运行环境进行样式自定义,例如pc/m)
titleStringtitle of dialog (弹窗标题)
widthNumber/String (width unit)width of dialog (弹窗宽度)
contentStringcontent of dialog (弹窗内容)
okfunctioncallback for ok botton/toast (确定按钮/toast回调)
cancelfunctioncallback for cancel button (取消按钮回调)
componentObjectcustom component object (自定义组件对象)
okEventObjectcustom ok event bus name (自定义确定 event bus 名称)
cancelEventObjectcustom cancel event bus name (自定义取消 event bus 名称)
disabledBoolendisable click the confirm (禁用确认按钮点击事件)
submitingBoolensubmiting style for confirm button (确认按钮正在提交样式)
shadowCloseBoolen (default : true)click shadow to close dialog (点击背景遮罩关闭弹窗)
okTextStringconfirm button text for alert (alert确认按钮文案)
confirmTextStringconfirm button text for confirm (confirm确认按钮文案)
cancelTextStringcancel button text (取消按钮文案)
timerNumbershow toast time (显示toast时长)
msgNumbershow toast msg (显示toast消息)
stopBodyScrollBoolen(default: true)stop Body Scroll, support pc & m (禁止body跟随弹窗内容区域滚动而滚动的默认行为, 同样支持移动端)

By the way:

u can use it like this (你可以这样引入):

1) no css

import Vue from 'vue';
import kdialog from 'vue-kdialog';
Vue.use(kdialog);

2) with postcss

import Vue from 'vue';
import kdialog from 'vue-kdialog';
import kdialog from 'vue-kdialog/src/keydialog_pc.css';
Vue.use(kdialog);

3) event bus & callback (内置了 event bus 和回调函数) There 2 ways to handle confirm & cancel button:

① event bus:

import Vue from 'vue';
import kdialog from 'vue-kdialog'
Vue.use(kdialog);
kdialog.eventbus();
// init the eventbus, the bus will be mounted to Vue prototype (全局使用eventbus事件,并挂载到vue原型上)

// when u need:
const this = vm;
vm.$bus.$off('changeAct'); // !!!!off event first!!!! of u will get more emit
vm.$confirm({
	title: '<h2>title with html</h2>'
	okEvent: 'changeAct',  // emit ok event, click the ok, it will emit 'changeAct'
	cancelEvent: 'cancelChangeAct',	// emit cancel event, click the ok, it will emit 'changeAct'
	componentData: {
		data:'something'
	}
});

vm.$bus.$on('changeAct', (data)=>{
	console.log(data);  // the dialog object
	console.log(data.$dialog.componentData); // {data:'something'}
	data.$dialog.close();
	//after close, the dialog, 'changeAct' & 'cancelChangeAct' events will be destroyed automatically, so please use different event name for every different dialog. 
	//(执行close方法后,当前弹窗实例和相应 event bus 事件会被自动销毁。所以请给不同的弹窗使用不同的 event 事件名称)
});

② callback

vm.$alert({
	title: 'gift'
	ok($dialog){  // ok callback
		console.log($dialog); // the $alert dialog itself;
	},
});

Tips (提醒)

1, Using it only u know it deeply, becourse u may receive multiple events. when event bus & callback use at same time, the callback will be priority.

1, 如果你不能熟练使用 event bus, 最好不要使用,因为使用不当可能会接收到多次提交事件。另外,当 event bus 和回调同时使用时,优先处理回调,所以你可以在开启 event bus 时按需使用回调来处理事务。

2, When building, getting error with webpack.optimize.uglifyjsplugin config, Using uglifyjs-webpack-plugin to instead of webpack.optimize.uglifyjsplugin, it should be fine.

2, 如果使用 webpack.optimize.uglifyjsplugin 打包过程中出现弹窗组件打包报错, 请换成 uglifyjs-webpack-plugin 去压缩你的 JS 文件, 应该就不会报错了。

API document (开发文档)

more to see: https://keydone.github.io/vue-kdialog/dist/examples.html

##1.0.3 new:

  • fix: bug in IE10.

##1.0.0 new:

  • stopBodyScroll for mobile is back since this version.

In pc, u just need add max-height, overflow-y:auto for dialog's content;

But, in mobile, u must put scroll content in 'kdialog_scroll_wrap', and add max-height;

##0.7.14 new:

  • import kdialog from 'vue-kdialog', but no css;
  • import 'vue-kdialog/src/keydialog_pc.css'; // browsers support: "last 20 versions", "ie >=9";(or scss)
  • Add set language: kdialog.setLanguage('en'); // only can be 'en'/'zh-cn'; default: 'zh-cn';
  • or kdialog.setLanguage({ ok: 'OK', confirm: 'Confirm', cancel: 'cancel' });

  • remove toastName & modalName, Add 'modal_enter', 'modal_leave' for animation;

##0.7.4 new:

  • stopBodyScroll: to stop body's scroll action while scrolling dialog content. (滚动弹窗内容阻止body滚动)

To be continued ! ( It will be strong )

未完待续。。。 ( 后续版本会更加强劲 )

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.7.15

6 years ago

0.7.14

6 years ago

0.7.13

6 years ago

0.7.12

6 years ago

0.7.11

6 years ago

0.7.10

6 years ago

0.7.7

6 years ago

0.7.6

6 years ago

0.7.5

6 years ago

0.7.4

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.7

6 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.4.5

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.2

6 years ago

0.1.3

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago