Skip to content

How do I declare code outside setup() in a script-setup SFC? #8653

Closed Answered by spaceemotion
spaceemotion asked this question in Help/Questions
Discussion options

You must be logged in to vote

I've used the Vue SFC Playground to expirement a bit and have found the following solution: Simply split up the script-setup into two script blocks to not have the compiler put the cva() calls inside the setup() method. Like so:

<script>
// Add all your cva() calls here
const button = cva();
</script>

<script setup>
// You can still use the button variable here
const classes = computed(() => button({}));
</script>

<template>
<!-- And even in the template it will work -->
</template>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by spaceemotion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant