add clickoutside

pull/2/head
qingwei.li 2016-07-28 12:20:21 +08:00
parent 287868d165
commit 8ec81da71b
3 changed files with 35 additions and 3 deletions

View File

@ -1,6 +1,6 @@
<template>
<div class="el-dialog__wrapper" v-if="visible" transition="dialog-fade" @click.self="handleWrapperClick">
<div class="el-dialog {{ sizeClass }} {{ customClass }}" v-el:dialog :style="{ 'margin-bottom': size !== 'full' ? '50px' : '', 'top': size !== 'full' ? dynamicTop + 'px' : '0' }">
<div class="el-dialog" :class="[sizeClass, customClass]" v-el:dialog :style="{ 'margin-bottom': size !== 'full' ? '50px' : '', 'top': size !== 'full' ? dynamicTop + 'px' : '0' }">
<div class="el-dialog__header">
<span class="el-dialog__title">{{title}}</span>
<div class="el-dialog__headerbtn">

View File

@ -11,7 +11,7 @@
@click="handleMiscClick"
:style="{ 'width': width + 'px' }"
transition="label-fade">
<i class="{{ onIconClass }}" v-if="onIconClass"></i>
<i :class="[onIconClass]" v-if="onIconClass"></i>
<span v-if="onText">{{ onText }}</span>
</div>
<div
@ -20,7 +20,7 @@
@click="handleMiscClick"
:style="{ 'width': width + 'px' }"
transition="label-fade">
<i class="{{ offIconClass }}" v-if="offIconClass"></i>
<i :class="[offIconClass]" v-if="offIconClass"></i>
<span v-if="offText">{{ offText }}</span>
</div>
</div>

32
src/utils/clickoutside.js Normal file
View File

@ -0,0 +1,32 @@
/**
* v-clickoutside
* @desc 点击元素外面才会触发的事件
* @example
* ```vue
* <div v-element-clickoutside="handleClose">
* ```
*/
let handler;
export default {
bind(el, binding, vnode) {
const expression = binding.expression;
handler = function(e) {
if (vnode.context && !el.contains(e.target)) {
vnode.context[expression]();
}
};
document.addEventListener('click', handler);
},
unbind() {
document.removeEventListener('click', handler);
},
install(Vue) {
Vue.directive('clickoutside', {
bind: this.bind,
unbind: this.unbind
});
}
};