Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "script setup" in VueJS 2.x

<script setup> is a compile-time syntactic sugar for using Composition API inside Single File Components (SFCs) used in VueJS 3.x. I'm trying to get it to work in VueJS 2.x. Composition API is available as a separate module that can be installed in Vue 2.x projects. I installed the package and it compiles and runs, but my bindings do not show anything in the output. Even the simplest ones like:

<script setup>
const msg = 'Hello!'
</script>

<template>
  <div>{{ msg }}</div>
</template>

do not show anything on the webpage. Am I missing something or does it not support Vue 2.x projects?

like image 400
dotNET Avatar asked Oct 28 '25 20:10

dotNET


2 Answers

According to the github repo, script setup is not part of the composition api and it's the compiler's job to implement this. You can read more in this Git Issue

There's a package that was created to implement this which you can find here, however it doesn't fully implement the spec and also seems to have some functional issues outside of that if you browse the repo.

In short, it doesn't seem worth it to use this in a production environment.

like image 55
Ohgodwhy Avatar answered Oct 31 '25 11:10

Ohgodwhy


Vue 2.7 supports <script setup>; see launch blog post

like image 29
mhjb Avatar answered Oct 31 '25 10:10

mhjb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!