提交 fb43c1f1 编写于 作者: D dolymood

refactor(mixin): remove parent mixin, use provide and inject

上级 a2079cb7
export default function parentMixinCreator (relationKey, targetKey = 'relationParent') {
return {
created() {
this[targetKey] = this._getTargetParent()
},
destroyed() {
this[targetKey] = null
},
methods: {
_getTargetParent() {
let p = this.$parent
while (p) {
if (p[relationKey]) {
return p
}
p = p.$parent
}
return null
}
}
}
}
......@@ -26,7 +26,6 @@
<script type="text/ecmascript-6">
import scrollMixin from '../../common/mixins/scroll'
import parentMixinCreator from '../../common/mixins/parent'
import CubeScroll from '../scroll/scroll.vue'
const DIRECTION_H = 'horizontal'
......@@ -37,7 +36,12 @@
export default {
name: COMPONENT_NAME,
mixins: [scrollMixin, parentMixinCreator('isScrollNav', 'scrollNav')],
inject: {
scrollNav: {
default: null
}
},
mixins: [scrollMixin],
props: {
direction: {
type: String,
......
......@@ -8,14 +8,13 @@
</template>
<script type="text/ecmascript-6">
import parentMixinCreator from '../../common/mixins/parent'
import CubeStickyEle from '../sticky/sticky-ele.vue'
const COMPONENT_NAME = 'cube-scroll-nav-panel'
export default {
name: COMPONENT_NAME,
mixins: [parentMixinCreator('isScrollNav', 'scrollNav')],
inject: ['scrollNav'],
props: {
label: {
type: [String, Number],
......
......@@ -54,6 +54,11 @@
export default {
name: COMPONENT_NAME,
provide() {
return {
scrollNav: this
}
},
mixins: [scrollMixin],
props: {
data: {
......@@ -97,9 +102,6 @@
this.$emit(EVENT_CHANGE, newVal)
}
},
beforeCreate() {
this.isScrollNav = true
},
created() {
this.navBar = null
this.panels = []
......
......@@ -7,13 +7,11 @@
</template>
<script type="text/ecmascript-6">
import parentMixinCreator from '../../common/mixins/parent'
const COMPONENT_NAME = 'cube-sticky-ele'
export default {
name: COMPONENT_NAME,
mixins: [parentMixinCreator('isSticky', 'sticky')],
inject: ['sticky'],
props: {
eleKey: {
type: [Number, String]
......
......@@ -26,6 +26,11 @@
export default {
name: COMPONENT_NAME,
provide() {
return {
sticky: this
}
},
props: {
pos: {
type: Number,
......@@ -106,9 +111,6 @@
this.$emit(EVENT_DIFF_CHANGE, newVal, height)
}
},
beforeCreate() {
this.isSticky = true
},
created() {
this.fixedEleHeight = 0
this.eles = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册