Skip to content

Commit

Permalink
refactor: OptionGroup重构为composition-api
Browse files Browse the repository at this point in the history
  • Loading branch information
yt0379 committed Sep 8, 2020
1 parent b5eb7b3 commit 99e828a
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions packages/option-group/OptionGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
</template>

<script type="text/babel">
import Emitter from 'element-ui/src/mixins/emitter'
import { useEmitter } from 'element-ui/src/use/emitter'
import {
watch,
getCurrentInstance,
onBeforeMount,
onMounted,
ref,
unref,
toRefs
} from 'vue'
export default {
mixins: [Emitter],
name: 'ElOptionGroup',
componentName: 'ElOptionGroup',
Expand All @@ -27,35 +34,34 @@ export default {
}
},
data() {
return {
visible: true
}
},
setup(props) {
const { disabled } = toRefs(props)
const visible = ref(true)
const { on, broadcast } = useEmitter()
const { ctx } = getCurrentInstance()
watch: {
disabled(val) {
this.broadcast('ElOption', 'handleGroupDisabled', val)
}
},
watch(disabled, (val) => {
broadcast('ElOption', 'handleGroupDisabled', val)
})
methods: {
queryChange() {
this.visible =
this.$children &&
Array.isArray(this.$children) &&
this.$children.some((option) => option.visible === true)
function queryChange() {
visible.value =
ctx.$children &&
Array.isArray(ctx.$children) &&
ctx.$children.some((option) => option.visible === true)
}
},
created() {
this.$on('queryChange', this.queryChange)
},
onBeforeMount(() => {
on('queryChange', queryChange)
})
mounted() {
if (this.disabled) {
this.broadcast('ElOption', 'handleGroupDisabled', this.disabled)
}
onMounted(() => {
if (unref(disabled)) {
broadcast('ElOption', 'handleGroupDisabled', unref(disabled))
}
})
return { visible }
}
}
</script>

0 comments on commit 99e828a

Please sign in to comment.