perf[TagsView]:use vue-clickaway to close context menu when you click outside of the component, and also make code neat

This commit is contained in:
hughdai 2018-10-24 16:32:34 +08:00
parent ec58373a52
commit c30d798f18
2 changed files with 4 additions and 8 deletions

View File

@ -55,6 +55,7 @@
"simplemde": "1.11.2", "simplemde": "1.11.2",
"sortablejs": "1.7.0", "sortablejs": "1.7.0",
"vue": "2.5.17", "vue": "2.5.17",
"vue-clickaway": "^2.2.2",
"vue-count-to": "1.0.13", "vue-count-to": "1.0.13",
"vue-i18n": "7.3.2", "vue-i18n": "7.3.2",
"vue-router": "3.0.1", "vue-router": "3.0.1",

View File

@ -15,7 +15,7 @@
<span class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" /> <span class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" />
</router-link> </router-link>
</scroll-pane> </scroll-pane>
<ul v-show="visible" :style="{left:left+'px',top:top+'px'}" class="contextmenu"> <ul v-on-clickaway="closeMenu" v-show="visible" :style="{left:left+'px',top:top+'px'}" class="contextmenu">
<li @click="refreshSelectedTag(selectedTag)">{{ $t('tagsView.refresh') }}</li> <li @click="refreshSelectedTag(selectedTag)">{{ $t('tagsView.refresh') }}</li>
<li @click="closeSelectedTag(selectedTag)">{{ $t('tagsView.close') }}</li> <li @click="closeSelectedTag(selectedTag)">{{ $t('tagsView.close') }}</li>
<li @click="closeOthersTags">{{ $t('tagsView.closeOthers') }}</li> <li @click="closeOthersTags">{{ $t('tagsView.closeOthers') }}</li>
@ -27,9 +27,11 @@
<script> <script>
import ScrollPane from '@/components/ScrollPane' import ScrollPane from '@/components/ScrollPane'
import { generateTitle } from '@/utils/i18n' import { generateTitle } from '@/utils/i18n'
import { mixin as clickaway } from 'vue-clickaway'
export default { export default {
components: { ScrollPane }, components: { ScrollPane },
mixins: [clickaway],
data() { data() {
return { return {
visible: false, visible: false,
@ -47,13 +49,6 @@ export default {
$route() { $route() {
this.addViewTags() this.addViewTags()
this.moveToCurrentTag() this.moveToCurrentTag()
},
visible(value) {
if (value) {
document.body.addEventListener('click', this.closeMenu)
} else {
document.body.removeEventListener('click', this.closeMenu)
}
} }
}, },
mounted() { mounted() {