You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In nuxt content, if we have a file pages/blog/[...slug].vue is there any way we can pass state into a content component, for example components/content/CodeBlock.vue?
An example I can think of is imagine in CodeBlock.vue you have some code like this:
If you have a blog post and you have 50 code blocks, now you also have 50 event listeners, this would be a good time to think about using event delegation. If we move the piece of code above into the file [...slug].vue now we can just use event delegation but there is a different problem now and that is we don't have the ability to update isActive.value = true.
In [...slug].vue
<script setup>
document.addEventListener('click', e=> {if (e.target.className==='.code-block') {// oops, access to child state lostisActive.value=true }})
</script>
Is there a way we could update the state from outside of the component or pass it down with props somehow?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In nuxt content, if we have a file
pages/blog/[...slug].vue
is there any way we can pass state into a content component, for examplecomponents/content/CodeBlock.vue
?An example I can think of is imagine in
CodeBlock.vue
you have some code like this:If you have a blog post and you have 50 code blocks, now you also have 50 event listeners, this would be a good time to think about using event delegation. If we move the piece of code above into the file
[...slug].vue
now we can just use event delegation but there is a different problem now and that is we don't have the ability to updateisActive.value = true
.In
[...slug].vue
Is there a way we could update the state from outside of the component or pass it down with props somehow?
Beta Was this translation helpful? Give feedback.
All reactions