[improvement] extract relation mixin

This commit is contained in:
陈嘉涵
2019-05-06 20:30:54 +08:00
parent 7014d67704
commit 8de7a287f6
3 changed files with 47 additions and 23 deletions

View File

@@ -2,34 +2,25 @@ import { use, isDef } from '../utils';
import Cell from '../cell';
import Icon from '../icon';
import Popup from '../popup';
import { ChildrenMixin } from '../mixins/relation';
const [sfc, bem] = use('dropdown-item');
export default sfc({
mixins: [ChildrenMixin('vanDropdownMenu')],
props: {
value: null,
title: String,
options: Array
},
inject: ['vanDropdownMenu'],
data() {
return {
show: false
};
},
created() {
const { items } = this.vanDropdownMenu;
const index = this.vanDropdownMenu.slots().indexOf(this.$vnode);
items.splice(index === -1 ? items.length : index, 0, this);
},
beforeDestroy() {
this.vanDropdownMenu.items = this.vanDropdownMenu.items.filter(item => item !== this);
},
computed: {
displayTitle() {
if (this.title) {
@@ -48,7 +39,7 @@ export default sfc({
},
render(h) {
const { top, zIndex, activeColor } = this.vanDropdownMenu;
const { top, zIndex, activeColor } = this.parent;
const Options = this.options.map(option => {
const active = option.value === this.value;