mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-02 11:17:46 +08:00
refactor(components): [collection] switch to script-setup syntax (#7710)
Co-authored-by: metanas <matanas@pre-history.com>
This commit is contained in:
parent
c77155b899
commit
9edd89c642
@ -75,6 +75,6 @@ describe('<ElCollectionItem />', () => {
|
||||
expect(childVm.itemMap.size).toBe(3)
|
||||
const items = childVm.getItems()
|
||||
expect(childVm.getItems()).toHaveLength(3)
|
||||
expect(items[0].ref).toBe(collectionItems.at(0).element)
|
||||
expect(items[0].ref).toBe(collectionItems.at(0)?.element)
|
||||
})
|
||||
})
|
||||
|
@ -2,10 +2,8 @@
|
||||
<slot />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue'
|
||||
|
||||
export default defineComponent({
|
||||
<script lang="ts" setup>
|
||||
defineOptions({
|
||||
name: 'ElCollectionItem',
|
||||
inheritAttrs: false,
|
||||
})
|
||||
|
@ -3,6 +3,7 @@ import Collection from './collection.vue'
|
||||
import CollectionItem from './collection-item.vue'
|
||||
|
||||
import type { InjectionKey } from 'vue'
|
||||
import type { SetupContext } from '@vue/runtime-core'
|
||||
import type {
|
||||
ElCollectionInjectionContext,
|
||||
ElCollectionItemInjectionContext,
|
||||
@ -35,10 +36,9 @@ export const createCollectionWithScope = (name: string) => {
|
||||
|
||||
const items = [...itemMap.values()]
|
||||
|
||||
const orderedItems = items.sort(
|
||||
return items.sort(
|
||||
(a, b) => orderedNodes.indexOf(a.ref!) - orderedNodes.indexOf(b.ref!)
|
||||
)
|
||||
return orderedItems
|
||||
}
|
||||
|
||||
provide(COLLECTION_INJECTION_KEY, {
|
||||
@ -52,7 +52,7 @@ export const createCollectionWithScope = (name: string) => {
|
||||
const ElCollectionItem = {
|
||||
...CollectionItem,
|
||||
name: COLLECTION_ITEM_NAME,
|
||||
setup(_, { attrs }) {
|
||||
setup(_, { attrs }: SetupContext) {
|
||||
const collectionItemRef = ref<HTMLElement | null>(null)
|
||||
const collectionInjection = inject(COLLECTION_INJECTION_KEY, undefined)!
|
||||
|
||||
|
@ -2,10 +2,8 @@
|
||||
<slot />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue'
|
||||
|
||||
export default defineComponent({
|
||||
<script lang="ts" setup>
|
||||
defineOptions({
|
||||
inheritAttrs: false,
|
||||
})
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user