Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Vue JS : use <script setup> ?


In vue demo3, why you are not using <script setup> ? Can you provide some examples ?
Best regards, Wilhem


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


Thanks a lot,
Best regards, Wilhem



Hi,

The script setup syntax has some advantages over <script> with setup(), we will be slowly migrating to this syntax in our subsequent releases.

Since script setup is compile-time syntactic sugar, it works the same as a setup() function, you don't need to include return object to use your variables inside the component template.

Usage examples:

<script setup>
// variable
const msg = "Hello!"

// functions
function log() {
console.log(msg)
}
</script>

<template>
<button @click="log">{{ msg }}</button>
</template>


Using Components:

<script setup>
import MyComponent from "./MyComponent.vue"
</script>

<template>
<MyComponent />
</template>


defineProps() & defineEmits()

<script setup>
const props = defineProps({
foo: String
})

const emit = defineEmits(["change", "delete"])
// setup code
</script>


For more information and examples check Vue official doc:

Regards,
Lauris Stepanovs,
Keenthemes Support Team


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(