"Enhancing Nuxt/Vue 2 Development with Typescript in VS Code's Convenient Props Autocomplete Feature

Transitioning from React to a Nuxt project, I've encountered an issue with setting up autocompletion for props in VSCode (Vetur is installed). Let me illustrate with an example using a prop named 'alignment':

ComponentA:

<template>
  <div :class="styles[alignment]">
    /* Some Content */
  </div>
</template>

<script lang="ts">
import Vue, { PropType } from "vue";
import styles from "./styles.module.scss?module";

type AlignmentOptions = "left" | "right" | "center";

export default Vue.extend({
  props: {
    alignment: {
      type: String as PropType<AlignmentOptions>,
      default: "left"
    }
  },
  data() {
    return {
      styles
    }
  }
});
</script>

ComponentB:

<template>
  <ComponentA /> // Expected VC Code suggestions on props here, but no luck 
</template>

<script lang="ts">
import Vue from "vue";
import ComponentA from "@/components/ComponentA"

export default Vue.extend({
  components: {
    ComponentA
  }
});
</script>

Check out this Screenshot for reference:

VSCode Props Autocompletion

Any advice or ideas on how to resolve this issue? Thank you!

Answer №1

Transitioning from WebStorm to VS Code presented me with a similar issue. The props autocompletion is actually an intelligent feature, and after doing some digging, I was able to discover a solution for it within VS Code.

To resolve this, make sure to download and install vetur and vue-intellisense, then follow the guidelines provided on https://github.com/CyCraft/vue-intellisense#readme

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to conceal an element within a component based on the current component being used with the router?

I have managed to hide an entire component, but I am unsure of how to show or hide specific elements within a component. export class AppComponent { headerFooterVisible: boolean; constructor(private router: Router) { router.events.subscribe(e =&g ...

retrieve a property value using a Vue directive

I've been working on a Vue directive that should return true if a permission matches with the user permissions stored in Vuex. However, I'm facing difficulties accessing the state properly. Within Vue components, I have no trouble accessing the ...

Steps for integrating .web extension files in React Native Web using Typescript

When using react native web, there is a potential to utilize files with extensions such as .web and .android. For example: myFile.web.js myFile.android.js These files can then be included like so: import myFile from './myFile'; React Native w ...

What is the widely used term for the container that allows for panning by dragging with a mouse?

I am looking to design a container that extends beyond the width of the page, allowing users to pan by dragging through empty space between controls without zooming in or out. What is this type of container control typically referred to as? I am intereste ...

Error encountered in sending server response to WhatsApp API cloud using webhooks in Node.js due to Typescript

Can you assist me with my issue? I'm developing an API using TypeScript and Node.js Express, utilizing Meta for WhatsApp API cloud usage. I've set up a webhook following the official documentation, but I'm facing an issue with conditional i ...

Tailored production method based on specific criteria

One of my challenges is to create a versatile factory method using typescript. The main objective is to initialize a class based on its name using generics, instead of employing if/else or switch statements. I am aiming for similar functionality as this ...

Is it feasible to deduce the generic type of a function by considering all remaining arguments?

I'm working with code that looks like this: type Boxed<T> = { inner: T } const box = <T>(inner: T): Boxed<T> => ({ inner }); function test<T extends Boxed<any>>(...args: T[]): T extends Boxed<infer I> ? I : ne ...

What's the reason for the malfunction of  ?

How can I add space between firstname and lastname using   in my code? Despite setting the character set to utf-8, the space is not being rendered correctly. I even tried using tab space, but it didn't work as expected. export class AppCompone ...

What is the best strategy for managing a sizable react application using react-query?

Since diving into React with functional components and react-query, I've been facing some confusion on how to properly organize my components. Typically, I design components by having a top-level component handle all data access and pass data down to ...

Exploring VueJS by enhancing lifecycle hooks in each component

My app features a loader screen that displays before the content is rendered, and then disappears once everything has loaded. While this setup works well for a few components or views, I am finding it tedious to add this functionality to every single one. ...

How can I activate intellisense in VSCode for a node .mjs project?

Currently, I am in the process of developing a node cli application within a sub-directory of my project. I have opted to use .mjs files for this project. My main query at the moment is whether there is a method to activate VSCode intellisense for this s ...

Error message: The function `useSession` is not defined within the Next.js

I'm currently working on a next.js project with next-auth, where I have successfully implemented the login functionality. However, I'm facing an issue when trying to use the session to fetch user data on a specific page. Whenever I attempt to use ...

What could be preventing me from setting a boolean variable within an Observable?

After retrieving data from the Service, I am attempting to hide a specific div element. Below is the HTML code: <progressbar *ngIf="isLoadingBootStockData" [value]="100" type="default"> </progressba ...

Error: Uncaught TypeError - Unable to assign a value to the 'status' property

Hello everyone, I am currently facing an issue with validating the response from my server using Axios in VueJS. axios.post('/login', { email: this.email, password: this.password }).then(response => { if (response.status == 200) { $ ...

Vue cookies experiencing issues with updating cookie values correctly

My goal is to store user preferences (maximum 2-3 users) in a cookie for easy access. Upon login, I first check if the 'users' cookie exists. If not, I create it. If it does exist, I check if the current user is included in the cookie. If not, I ...

Enhance a function by sending it back to save static variables

I have a similar function like this one: export const bar = function () { const myItem = new MyItem(); return function bar(param1?: number, param2?: string): void{ ... }; }(); Where myItem is a variable that I use as a temporary inside ...

utilizing vue model attributes with `${}`

I am encountering an issue with my code. Initially, :src="labels[index]" was working fine for me. However, as my codebase expanded, I needed to use ${app.labels[index]}. Simply using ${app.labels} works, but the addition of [index] causes it to b ...

Is there a way to properly assign an index to a multidimensional array in a Vue.js template?

My setup involves utilizing Vue along with a multidimensional array structured like this: myArray = [[1,2,3],[1,2,3],[1,2,3]] To achieve the desired HTML layout shown below (ensuring that data-item counter increments correctly): <div class="row" data ...

Resizing svg to accommodate a circle shape

As I work on my vue.js app that involves a plethora of diverse icons, I made the decision to create a small icons builder in node.js. The purpose is to standardize their usage and also "crop" each SVG so it fits perfectly within its parent container by uti ...

Unresolved (waiting for response) unidentified

I encountered a perplexing error in Chrome and I am unable to identify its source: https://i.sstatic.net/f9Blt.png The only clue I have is that after refactoring approximately 10,000 lines of code, this error surfaced. It occurred during the middle of the ...