N
Nuxt2y ago
Nawi

How to get my body to change to green when drawer is open ?

<script setup lang="ts">
const runtime = useAppConfig();

const publicDrawer = useState<boolean | undefined | null>("publicDrawer")

useHead({
meta: [
{ name: "theme-color", content: runtime.theme.colors.primary },
{ name: "site-name", content: runtime.title },
{ name: "title", content: runtime.title },
],
bodyAttrs: {
class: publicDrawer ? "bg-red-900" : "bg-green-900",
},
});
</script>
<script setup lang="ts">
const runtime = useAppConfig();

const publicDrawer = useState<boolean | undefined | null>("publicDrawer")

useHead({
meta: [
{ name: "theme-color", content: runtime.theme.colors.primary },
{ name: "site-name", content: runtime.title },
{ name: "title", content: runtime.title },
],
bodyAttrs: {
class: publicDrawer ? "bg-red-900" : "bg-green-900",
},
});
</script>
right now it is not reactive, only red is applied.
3 Replies
conner
conner2y ago
Hey @Nawi. This will work:
useHead({
bodyAttrs: {
class: () => publicDrawer.value === false ? 'bg-green-900' : 'bg-red-900'
},
});
useHead({
bodyAttrs: {
class: () => publicDrawer.value === false ? 'bg-green-900' : 'bg-red-900'
},
});
You have to put in a computed getter, and also publicDrawer should everytime be defined (the whole state object), maybe you have to check for value.
Nawi
NawiOP2y ago
Works like a charm, Thank you @conner
conner
conner2y ago
No problem @Nawi
Want results from more Discord servers?
Add your server