Incorporating imports disrupts the script configuration in Nuxtjs 3

Issues arise when utilizing the import statement within the context of <script setup>, causing subsequent code to malfunction.

After installing the @heroicons package and importing it as a component in the <template>, all code below the import statements appears to stop working. Here is an example of the code:

<template>
  <HomeIcon class="w-5 h-5">
  <h1>{{myName}}</h1>
</template>

<script setup>
import {HomeIcon} from '@heroicons/vue/24/outline'

const myName = ref('username')
</script>

Upon running the provided code, the expected "username" heading is not displayed. Additionally, an ESLint warning occurs:

myName is declared but its value is never read

Remarkably, by commenting out the import statement, the myName ref appears to function properly once more.

Tools and packages used:

  • VS Code
  • Nuxtjs 3
  • Tailwind CSS
  • Heroicons package
  • PNPM as package manager

Answer №2

To improve efficiency, I have separated the import statement into a distinct <script> tag and exported it as a component. Now, my code consists of two <script> tags, one with the 'setup' attribute and one without.

Here is my final code:

<template>
    <HomeIcon class="w-5 h-5" />
    <h1>{{ myName }}</h1>
</template>

<script>
import { HomeIcon } from '@heroicons/vue/24/outline';

export default {
    components: {
        HomeIcon,
    },
};
</script>

<script setup>
const myName = ref('username');
</script>

Despite the functionality appearing to be correct within the <script setup>, my linter plugin does not seem to recognize that the declared variable is being utilized (refer to img1). img1

Here are some of the plugins I am utilizing:

  • ESLint
  • Javascript (ES6) code snippets
  • Prettier
  • Vetur
  • Vue Language Features (Volar)

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 automate the duplication/copying of files using JavaScript?

I have a GIF file stored in the "assets" directory on my computer. I want to create multiple duplicates of this file within the same directory, each with a unique filename. For example: If there is a GIF file named "0.gif" in the assets directory, I woul ...

Show React compilation errors

Whenever I used to start React as per their tutorial, it would show compile errors in this specific scenario. However, after setting up a webpack configuration for a React project, if there are compilation errors, the page simply remains blank. Is there ...

Deleting a document by ObjectID in MongoDB with Node and Express without using Mongoose: A step-by-step guide

As a newcomer to backend development, I am currently using Node/Express/MongoDB with an EJS template for the frontend. I am in the process of creating a simple todo list app to practice CRUD operations without relying on Mongoose but solely native MongoDB. ...

`To transfer the selected radio button value to a different form field using jquery, follow these steps.`

I need to set either the value no or 1 for the input field name="auth[]" below. <td> send <input type="radio" name="authorized[]'.$c.'" id="send'.$c.'"value="1" checked> </td> <td> no <input label=" ...

How to simulate keyboard events when a dropdown list is opened in an Angular application

Requirement- A situation arises where upon opening the dropdown menu, pressing the delete key on the keyboard should reset the index to -1. Steps to reproduce the issue: 1. Click on the dropdown and select an option from the menu. 2. Click on the dropdow ...

Guide on automatically filling input text fields with database values when a checkbox is clicked

I need to automate the process of filling in multiple input text fields with values from variables retrieved through a SELECT query when a checkbox is clicked. For instance, if the SELECT query returns the Warehouse Street Address ($WarehouseStreetAddres ...

What exactly does the symbol *:* signify in VueJS?

As I was delving into a Vue code, I came across the following snippet: <q-field v-if="isEditing" :label="to.label" :helper="helper" I'm puzzled by what :label="to.label" signifies in VueJS. Could someone shed light on this for ...

Which option is the speediest: using script setup or the setup function?

When working with Vue3, which method is more efficient in terms of speed: <script setup></script> <!-- Option 1 --> <script>setup() return {}</script> <!-- Option 2 --> ...

Where is the ideal location to store non-component data properties in Vue.js?

Currently, I am in the midst of a Vue.js project where components are predominantly used. However, there are moments when I simply need to incorporate some Vue.js syntax without creating an entire component. Since I am not utilizing the render function as ...

Ways of extracting specific information from a JSON file with the help of jQuery

I am currently attempting to parse a JSON file that is stored locally on my system using jQuery. I am specifically interested in retrieving certain data from the file, which is structured like this: {"statements":[{"subject":{"uriString":"A","localNameIdx ...

Efficiently styling table Spans with styled components in React

Can anyone help me with a frustrating CSS problem I'm facing? I am trying to render these tags as spans, but they are not separating properly as shown in the image below. They appear stuck together and I can't figure out why. I am using styled co ...

Having issues with the functionality of jQuery. It needs to be able to override existing

I am trying to make it so that if yes2 == none, the element with class .bottomandroid is removed and instead, the element with class .cta is displayed. However, it doesn't seem to be working as expected. How can I fix this issue? else if (isAndroid) ...

What is the reason for me continuously receiving the error "cannot read map of undefined"?

Having trouble debugging my redux sagas and react integration. No matter what initial state I set, I keep running into undefined errors when trying to map through the data. I've tried null, undefined, and empty arrays but nothing seems to work. Can a ...

Using the Mongoose $or operator with a nested array in query conditions

Here are the schemas I am using: //ProjectModel const ProjectSchema: Schema = new Schema( owner: { type: Schema.Types.ObjectId, ref: "User" }, users: [{type: Schema.Types.ObjectId, ref: "ProjectUser", unique: true }] ); //Project Use ...

Struggling to adjust the quantity of items in a basic shopping cart when adding multiples of the same item

Hello there! I'm currently working on a project where I need to increase the quantity of each item added to the cart if it's already in there. This is actually my first time posting, so any tips on asking better questions would be greatly appreci ...

Unable to retrieve JSON data for the JavaScript object

I have been working on creating a JS object in the following manner var eleDetailsTop = new Array(); var j = 0; var id = "ele"+j; eleDetailsTop[id] = {id: id, size : "40%", sizeLabel : 12, type : "image", title : "Image& ...

I encountered a sudden halt in functionality with my NextJs useState feature

'use client' import React, { useState } from 'react'; import Image from 'next/image'; export default function Home() { const [count,setCount] = useState<number>(0) const add = ()=> { setCount(prevCount => ...

What is the mechanism behind the jQuery ready function that enables its first parameter to transform into a jQuery object?

While browsing today, I came across this interesting code snippet: jQuery(document).ready(function($$){ console.log($$); }); It seems that $$ is recognized as the jQuery object itself. Typically, to achieve this, we would need to pass the jQuery varia ...

Is it better to use AngularJS' ngMock inject before each test or for each individual test case?

Current Situation As I work on writing tests for an Angular project, I have come across a common practice of creating "global" variables in a describe block to store dependencies needed for the tests. This approach involves defining variables like $contro ...

Unlocking Node.js packages within React JS is a seamless process

Currently, I am developing a React Serverless App with AWS. I am looking for ways to incorporate a Node JS specific package into the React JS code without requiring Node JS on the backend. One package that I need access to is font-list, which enables list ...