提交 c9b9f006 编写于 作者: fxy060608's avatar fxy060608

Update uni-collapse.vue

上级 683b8fe1
<template> <template>
<!-- 父组件暂时无用,后续子组件联动需要使用到父组件 --> <!-- 父组件暂时无用,后续子组件联动需要使用到父组件 -->
<view> <view>
<slot></slot> <slot></slot>
</view> </view>
</template> </template>
<script lang="uts"> <script lang="uts">
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
export default { export default {
name: "UniCollapse", name: "UniCollapse",
props: { props: {
// 是否开启手风琴效果 // 是否开启手风琴效果
accordion: { accordion: {
type: Boolean, type: Boolean,
default: true default: true
} }
}, },
data() { data() {
return { return {
child_nodes: [] as Array < ComponentPublicInstance > child_nodes: [] as Array < ComponentPublicInstance >
}; };
}, },
methods: { methods: {
init(child: ComponentPublicInstance) { init(child: ComponentPublicInstance) {
this.child_nodes.push(child) this.child_nodes.push(child)
}, },
// 关闭所有 // 关闭所有
cloceAll() { cloceAll() {
// 开启手风琴效果才回关闭其他 // 开启手风琴效果才回关闭其他
if (this.accordion && this.child_nodes.length > 0) { if (this.accordion && this.child_nodes.length > 0) {
this.child_nodes.forEach((item) => { this.child_nodes.forEach((item) => {
const is_open = item.$data.get('is_open') as boolean const is_open = item.$data['is_open'] as boolean
// TODO 暂时无法获取子组件上的属性和方法,暂时使用绕过方案 // TODO 暂时无法获取子组件上的属性和方法,暂时使用绕过方案
if (is_open) { if (is_open) {
item.$data.set('is_open', false) item.$data['is_open'] = false
item.$callMethod('oepnOrClose', false) item.$callMethod('oepnOrClose', false)
} }
}) })
} }
} }
} }
} }
</script> </script>
<style> <style>
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册