VueJS3 ref/reactive 对象键数组

VueJS3 ref/reactive array of object keys

我想在普通 Vue 组件之外查看对象的键。

我认为 reactive 应该可以做到这样的事情,但还没有运气:

var myObject = {};
var keys = reactive(Object.keys(myObject));

myObject['fish'] = 200;
//keys is still []

也尝试过:

var keys = reactive({keylist: Object.keys(myObject)});

var keys = ref(Object.keys(myObject));

终于明白了,是reactivewatchEffect的组合。如果这是 anti-pattern 不知何故,我仍然愿意接受更清晰的答案。

var myObject = reactive({});
var keys;
watchEffect(() => {
    keys = Object.keys(myObject);
});