mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 18:36:51 +08:00
[new feature] optimize find-parent (#325)
* fix: Tabbar icon line-height * [new feature] progress add showPivot prop * [new feature] TabItem support vue-router * [new feature] update document header style * [Doc] add toast english ducoment * [bugfix] Search box-sizing wrong * [Doc] update vant-demo respo * [Doc] translate theme & demo pages * [Doc] add Internationalization document * [bugfix] remove unnecessary props * [fix] optimize clickoutside * [new feature] optimize find-parent
This commit is contained in:
parent
cd0a0bc8f9
commit
2890a55ed8
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import findParent from '../mixins/findParent';
|
import findParent from '../mixins/find-parent';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'van-checkbox',
|
name: 'van-checkbox',
|
||||||
@ -52,7 +52,7 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
// whether is in van-checkbox-group
|
// whether is in van-checkbox-group
|
||||||
isGroup() {
|
isGroup() {
|
||||||
return !!this.findParentByComponentName('van-checkbox-group');
|
return !!this.findParentByName('van-checkbox-group');
|
||||||
},
|
},
|
||||||
|
|
||||||
currentValue: {
|
currentValue: {
|
||||||
|
22
packages/mixins/find-parent.js
Normal file
22
packages/mixins/find-parent.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* find parent component by name
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
findParentByName(name) {
|
||||||
|
if (!this.parentGroup) {
|
||||||
|
let parent = this.$parent;
|
||||||
|
while (parent) {
|
||||||
|
if (parent.$options.name === name) {
|
||||||
|
this.parentGroup = parent;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
parent = parent.$parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.parentGroup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
@ -1,22 +0,0 @@
|
|||||||
/**
|
|
||||||
* 根据父组件名找到对应`parent`
|
|
||||||
*/
|
|
||||||
export default {
|
|
||||||
methods: {
|
|
||||||
findParentByComponentName(name) {
|
|
||||||
if (this.parentGroup) return;
|
|
||||||
|
|
||||||
let parent = this.$parent;
|
|
||||||
while (parent) {
|
|
||||||
if (parent.$options.name === name) {
|
|
||||||
this.parentGroup = parent;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
parent = parent.$parent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.parentGroup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
@ -25,7 +25,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import findParent from '../mixins/findParent';
|
import findParent from '../mixins/find-parent';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'van-radio',
|
name: 'van-radio',
|
||||||
@ -40,7 +40,7 @@ export default {
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
isGroup() {
|
isGroup() {
|
||||||
return !!this.findParentByComponentName('van-radio-group');
|
return !!this.findParentByName('van-radio-group');
|
||||||
},
|
},
|
||||||
|
|
||||||
currentValue: {
|
currentValue: {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import findParent from '../mixins/findParent';
|
import findParent from '../mixins/find-parent';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'van-tab',
|
name: 'van-tab',
|
||||||
@ -21,7 +21,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
this.findParentByComponentName('van-tabs');
|
this.findParentByName('van-tabs');
|
||||||
const nextIndex = this.parentGroup.tabs.length;
|
const nextIndex = this.parentGroup.tabs.length;
|
||||||
this.updateParentData(nextIndex);
|
this.updateParentData(nextIndex);
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user