vetur icon indicating copy to clipboard operation
vetur copied to clipboard

Supporting <script setup>

Open boonyasukd opened this issue 5 years ago • 39 comments

  • [x] I have searched through existing issues

Feature Request

Earlier this year Evan introduced a new RFC to improve upon the script section to support <script setup>. This RFC is already included as part of the vue@next, and vue-loader was recently updated to support it, so it's my hope that vetur will update to support this as well, since without it intellisense doesn't work correctly. The error I got was

File '/path/to/component/HelloWorld.vue' is not a module. Vetur(2306)
Screen Shot 2020-09-21 at 00 22 58

boonyasukd avatar Sep 20 '20 17:09 boonyasukd

nice but hack

cereschen avatar Sep 21 '20 01:09 cereschen

one more could support. like bellow:

<script setup="props, { emit }" lang="ts">
export const handleClick = (evt) => {
  emit('click', evt);
};
</script>

image

akai007 avatar Sep 21 '20 03:09 akai007

This feature need to add wrapper code like template Interpolation.

yoyo930021 avatar Sep 21 '20 03:09 yoyo930021

async setup should be considered also, e.G.

SomeComponent.vue

<template>
  <Container title="Domains">
    <template #breadcrumb>
      <Breadcrumb
        :routes="[
          { title: 'Dashboard', name: Routes.DASHBOARD },
          { title: 'Domains', name: Routes.DOMAIN_LIST },
        ]"
      />
    </template>
    <template #content>
      <Table />
    </template>
  </Container>
</template>

<script lang="ts" async setup>
export { default as Container } from '@/modules/ui/components/Container.vue'
export { default as Table } from '@/modules/domain/components/domain/Table.vue'
export { default as Breadcrumb } from '@/modules/ui/components/Breadcrumb.vue'
export { Routes } from '@/router'

// some async operation
export const foo = await ....

export default {}
</script>

soerenmartius avatar Sep 23 '20 11:09 soerenmartius

When using export default it also not recognize props.

Component.vue

<template>
  <h1>{{ msg }}</h1>
  <button @click="count++">count is: {{ count }}</button>
</template>

<script setup="props" lang="ts" async>
import { ref } from 'vue';

export default {
  props: {
    msg: {
      type: String,
      default: 'default msg',
    },
  },
};

console.log(props.msg); // Cannot find name 'props'.Vetur(2304)

export const count = ref(0);
</script>

fajuchem avatar Oct 18 '20 02:10 fajuchem

I don't know how the language server is implemented underneath, but @vue/compiler-sfc already supports this, so it would just be a matter of using it to codegen the required information.

ambyjkl avatar Oct 19 '20 23:10 ambyjkl

I don't know how the language server is implemented underneath, but @vue/compiler-sfc already supports this, so it would just be a matter of using it to codegen the required information.

It's actually not that simple. It involves monorepo support and code conversion. This will be my next work after monorepo support.

yoyo930021 avatar Oct 20 '20 01:10 yoyo930021

Is there a way to disable <script setup>-related errors in Vetur / work around them somehow without turning off all validations? Would like to upgrade my code to the new syntax.

I know it's very early days still, Thank You all for your hard work with Vetur 👍

Uninen avatar Nov 26 '20 14:11 Uninen

@Uninen If you look at recent changes made to vitepress, Evan seems to suggest the team to use Volar instead of Vetur for now, so maybe you can try using that until Vetur is up-to-date.

boonyasukd avatar Nov 26 '20 15:11 boonyasukd

yo. Any news on this one ?

CaptainYouz avatar May 15 '21 14:05 CaptainYouz

2 month bump 🎂

xon52 avatar Jul 16 '21 09:07 xon52

+1.

cweijan avatar Jul 21 '21 12:07 cweijan

https://twitter.com/NikhilVerma/status/1405199735107973120 + reply

ghost avatar Jul 21 '21 12:07 ghost

Now that Vue 3.2 is out with stable support for this, is this landing soon?

arafatamim avatar Aug 10 '21 11:08 arafatamim

any update about this?

hi-reeve avatar Sep 09 '21 02:09 hi-reeve

@zynth17, @arafatamim, and others

If you take a look at how Evan recently responded about the recommended approach going forward, it seems that volar is currently the extension of choice for vue 3.

I've been using volar for several months, and so far the auto-completion in both <script> and <template> section has been nice. It's doubly nice if the component library you use is developed in TS and provide thorough typing information for VLS to work things out, since it catches a lot of misspellings, and you can simply hover your mouse to see type info of each variable:

Screen Shot 2021-09-09 at 11 50 09

boonyasukd avatar Sep 09 '21 05:09 boonyasukd

@zynth17, @arafatamim, and others

If you take a look at how Evan recently responded about the recommended approach going forward, it seems that volar is currently the extension of choice for vue 3.

I've been using volar for several months, and so far the auto-completion in both <script> and <template> section has been nice. It's doubly nice if the component library you use is developed in TS and provide thorough typing information for VLS to work things out, since it catches a lot of misspellings, and you can simply hover your mouse to see type info of each variable:

Screen Shot 2021-09-09 at 11 50 09

i do love volar but what i dont like from volar is it doesn't support the autoclosing tag you need to close bracket, or parentheses even quote manually. it's just very annoying to do it manually. anyway thanks for the suggestion, i will try to use volar for now at least

hi-reeve avatar Sep 09 '21 07:09 hi-reeve

@boonyasukd Does that mean that Vetur has no close plans to implement <script setup> any time soon?

ivan-bragin avatar Oct 03 '21 21:10 ivan-bragin

@ivan-bragin That I don't really know. I'm just a regular vue user who happens to follow Evan closely on Twitter and Github, so I noticed the change in recommendation. If you want to know that, you probably have to ask vetur maintainer(s).

boonyasukd avatar Oct 03 '21 23:10 boonyasukd

Yeah having this feature would be awesome,,, I don't want to switch to volar,, I like vetur more,

JenuelDev avatar Oct 18 '21 02:10 JenuelDev

We plan to support it in next next version. (v0.37.0) But there is no schedule, it is a big work.

yoyo930021 avatar Oct 18 '21 02:10 yoyo930021

Hey everyone.

What's the status here?

Miguel-Bento-Github avatar Dec 06 '21 14:12 Miguel-Bento-Github

I have two solutions to avoid this error for now

  1. change to
  1. Add a script tag at the top of the Vue file to declare the name attribute

zxhhh11 avatar Dec 15 '21 03:12 zxhhh11

For now can just disable Vetur for script section and use ESlint, TSLint

VS Code JSON config line "vetur.validation.script": false,

goshander avatar Dec 16 '21 19:12 goshander

For now can just disable Vetur for script section and use ESlint, TSLint

VS Code JSON config line "vetur.validation.script": false,

Currently, I had Vue 2 project but using the

And disabling script validation working at least for now. If you're using Typescript, it's recommended to disable interpolation validation too. "vetur.validation.interpolation": false The error on the template will be gone. We don't get any autocomplete on the template, but it's okay for now, we still can use runtime error for that.

wahyubucil avatar Dec 19 '21 03:12 wahyubucil

Just a heads up if you installed volar to get the setup support it seems like you also have to uninstall vetur as well in order to get it to work. (at least thats what I had to do)

tomcorey26 avatar Jan 23 '22 17:01 tomcorey26

Just a heads up if you installed volar to get the setup support it seems like you also have to uninstall vetur as well in order to get it to work. (at least thats what I had to do)

Yeah, the best is to create a workspace with Vetur disabled, it might be that you have projects without the setup script.

Miguel-Bento-Github avatar Jan 24 '22 14:01 Miguel-Bento-Github

<script setup=""> works. I've found no other working solution so far

tarkhil avatar Feb 10 '22 07:02 tarkhil

You should be using volar nowadays. It has superseded vetur afaik. I don’t think it makes much sense to also implement setup support here. What are the official plans for vetur, @octref, @yoyo930021?

bodograumann avatar Feb 10 '22 08:02 bodograumann

Sorry, not very related to this thread, but please upvote microsoft/vscode#143531 to get more Vue 3 users to Volar ;)

zigomir avatar Feb 18 '22 09:02 zigomir