Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: Can't use <script setup> with Vue 3 #1190

Closed
Miguelklappes opened this issue Aug 21, 2021 · 5 comments
Closed

🐛 BUG: Can't use <script setup> with Vue 3 #1190

Miguelklappes opened this issue Aug 21, 2021 · 5 comments
Labels
pkg: vue Related to Vue (scope)

Comments

@Miguelklappes
Copy link

What package manager are you using?

yarn

What operating system are you using?

Windows

Describe the Bug

I can't use the <script setup> syntax with Vue 3, therefore I am not able to take advantage of some features of this framework.

Steps to Reproduce

  1. yarn create astro -- --template framework-vue
  2. yarn && yarn dev
  3. Edit Vue component and use <script setup> syntax
  4. Wait for it to work and it doesn't
  5. The errors are the usual Vue warn that happens when you forgot to return something in the setup() function, but here I am using <script setup>, thus properties are always exposed. I expected <script setup> to work as usual.

[Vue warn]: Property "count" was accessed during render but is not defined on instance.

Link to Minimal Reproducible Example (Optional)

https://github.com/Miguelklappes/astro-test

@itday
Copy link

itday commented Aug 26, 2021

The example is reproducible.

In Astro, Vue is supported trough Vue Loader. Unfortunately, this "new" feature is not supported in the Vue loader. There is an open issue in the Vue loader project: vuejs/vue-loader#1804

Currently supported in Astro:

<script>
import {ref} from 'vue';

export default {
  setup() {
    const count = ref(0)
    const add = () => count.value = count.value + 1;
    const subtract = () => count.value = count.value - 1;

    return {
      count,
      add,
      subtract
    }
  }
}
</script>

Supported in native Vue with less boilerplate code:

<script setup>
import { ref } from 'vue';

const count = ref(10);
const add = () => (count.value = count.value + 1);
const subtract = () => (count.value = count.value - 1);
</script>

@matthewp

@matthewp
Copy link
Contributor

Are you sure that we use Vue Loader? I don't see a reference to it. Anyways, thanks for confirming the bug!

@matthewp
Copy link
Contributor

I guess the fix is to use the Vue compiler directly.

@drwpow drwpow added the pkg: vue Related to Vue (scope) label Oct 20, 2021
@Igloczek
Copy link
Contributor

Igloczek commented Oct 26, 2021

It's a sugar syntax that vue-loader, and for example Vue plugin for Vite, have implemented and works fine, despite the previous comments. It's not going to be part of the Vue compiler.

So in my opinion, there is no point to wait for anything else than Vite, because otherwise we will have to add support for it to Snowpack Vue plugin.

@FredKSchott
Copy link
Member

Thanks for the report! We believe that this has been fixed in astro v0.21, going out today. Let us know if you can still reproduce the issue after updating to v0.21 and we'll be happy to take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: vue Related to Vue (scope)
Projects
None yet
Development

No branches or pull requests

6 participants