nuxt-jsonld icon indicating copy to clipboard operation
nuxt-jsonld copied to clipboard

Handle `MaybeComputedRef` for UseJsonld input field

Open ymmooot opened this issue 2 years ago • 2 comments

Currently, useHead can handle MaybeComputedRef like below:

// static
useHead({
  title: "title",
});
// function
useHead(() => ({
  title: someRef,
}))
// ref, computed, and reactive
useHead({  
  title: someRef,  
})

useJsonld can only handle a static object and a function.

// static
useJsonld({
  name: "title",
});
// function
useJsonld(() => ({
  name: someRef.value, // .value needed
}))
  • [ ] Handle MaybeComputedRef like useHead
  • [ ] Fix broken link to useHead in README

working on nuxt-jsonld/tree/reactive

ymmooot avatar Jan 25 '23 14:01 ymmooot

Any update? I am trying to use a computedRef inside of useJsonld and I am getting this error:

"Converting circular structure to JSON\n --> starting at object with constructor 'ComputedRefImpl'\n | property 'effect' -> object with constructor 'ReactiveEffect'\n --- property 'computed' closes the circle",

TimGuendel avatar Nov 28 '23 10:11 TimGuendel

Hi @TimGuendel. Currently you can not pass a computed value directly:

// This does not work
const nameComputed = computed(() => 'Alice');
ustJsonld({
    name: nameComputed,
});

However, you can do this:

// This works fine
const nameComputed = computed(() => 'Alice');
ustJsonld(() => ({
    name: nameComputed.value,
}));

Converting circular structure to JSON

Please make sure there are no circular references in your object.

ymmooot avatar Nov 28 '23 15:11 ymmooot