<template>
    <el-card> 获取对象中属性为Symbol类型的方法 </el-card>
</template>

<script setup lang="jsx">
import { onMounted } from 'vue';

onMounted(() => {
    getSymbolObject();
});

const getSymbolObject = () => {
    const sym = Symbol('dynamicModuleA');
    const obj = {
        [sym]: '我是Symbol属性的值',
    };

    /**
     * 获取对象的属性为Symbol类型方法
     * 错误写法:
     * for (const key in obj) {
     *     console.log(obj[key]);
     * }
     */
    const keys = Reflect.ownKeys(obj); //这里是重点实现
    console.log(keys);
    keys.forEach((key) => {
        console.log(obj[key]);
    });
};
</script>

<style lang="scss" scoped></style>
