In Production environment, v-model triggers a ReferenceError

My Vue View includes the following code:

<script setup>
import Overwrite from "../components/Overwrite.vue";
</script>
<template>
  <div>

      ...

      <textarea v-model="text" cols="99" rows="20"></textarea>

      ... 

  </div>
</template>

<script>
export default {
  data() {
    return {
      text: ""
    };
  },
  components: { Overwrite: Overwrite },
};
</script>

During development, everything functions correctly when using npm run dev.

However, after building the application for production and running it, I encounter an error as soon as content is typed into the textarea:

index.57b77955.js:3 Uncaught ReferenceError: text is not defined
    at HTMLTextAreaElement.t.onUpdate:modelValue.s.<computed>.s.<computed> [as _assign] (index.57b77955.js:3:1772)
    at HTMLTextAreaElement.<anonymous> (vendor.31761432.js:1:53163)

This issue also affects other form elements within the application.

Answer №1

Limit the usage to only 1 <script> tag and 1 <script setup> per Vue component.

Their outputs will be combined, and the resulting object from merging their exports will be accessible in <template>.

However, it's important to note that they are not linked. This means that one script tag cannot access the imports of the other.

An issue arises when the first <script setup> declares Overwrite upon importing it (to be used in

<template></code), but the second script overwrites it by using <code>components: { Overwrite: Overwrite }
, as Overwrite is undefined in the second script. This results in:

components: { Overwrite: undefined }

, hence overriding the value set by <script setup>.


There are two potential solutions:

Solution A:

<script>
import Overwrite from "../components/Overwrite.vue";
export default {
  components: {
    Overwrite
  },
  // Use `setup` instead of `data`
  setup: () => ({
    text: ref('')
  })
}
</script>

Solution B:

<script setup>
import Overwrite from "../components/Overwrite.vue";
const text = ref('')
</script>

Alternatively:

<script setup>
import Overwrite from "../components/Overwrite.vue";
</script>
<script>
export default {
  data: () => ({ text: "" })
};
</script>

Answer №2

Is it worth trying to utilize solely the setup script tag? It seems counterintuitive to use it only for imports in this manner. If you're importing a component within setup script tags, there's no need to specify components - perhaps the issue stems from that.

Alternatively, you could experiment with the complete setup approach:

<script setup>
import { ref } from 'vue'
import Overwrite from "../components/Overwrite.vue";

const text = ref('')
</script>

<template>
  <div>

      ...

      <textarea v-model="text" cols="99" rows="20"></textarea>

      ... 

  </div>
</template>

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

Having trouble starting the server? [Trying to launch a basic HTML application using npm install -g serve]

I am in the process of creating a PWA, but I haven't reached that stage yet. Currently, I have only created an index.html file and an empty app.js. To serve my project locally, I installed serve globally using npm install -g serve When I run the co ...

When PHP echo of json_encode triggers an error, AJAX status 200 will be raised

Despite everything running smoothly in the program below, an AJAX error is triggered: javascript: var data = { email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="026f6742656f636b6e2c616d6f">[email protect ...

Maintain the current application state within a modal until the subsequent click using Jquery

Due to the challenges faced with drag and drop functionality on slow mobile devices, I am considering implementing a modal approach for moving elements from one place to another. Here is how it would work: When a user clicks on an item, it is visually ma ...

What is the best way to invert the positioning of the li elements to move upwards?

https://i.stack.imgur.com/mZaoS.png Seeking assistance on adjusting the height of bars to start from the bottom and go upwards instead of starting from the top position and going downwards. The JavaScript code below is used to generate the li elements and ...

Choose information based on the prior choice made

Using the Material UI Stepper, I have a task that involves setting conditions based on the selection of checkboxes. In step one, there are two checkboxes - Individual and Bulk. In step two, there are also two checkboxes - First Screening and Second Screeni ...

transferring data to Amazon Web Services using Angular framework

I'm currently facing an issue while trying to send a file to an AWS server using an Angular dropzone. I have my AWS credentials ready, but I am unsure of how to properly make the request. Every time I attempt to drop the file into the dropzone, I kee ...

Error 405 (Unauthorized) encountered with the stack of technologies including Vue.js, Nginx, Axios, SQLite, and Express

I successfully developed an application that handles user login and registration to a SQLite database on `localhost`, but I am encountering issues when trying to deploy it. The deployment results in an error message saying `405 (Not Allowed)` with the acco ...

Updating the Homebrew Cache

Currently utilizing the MacintheCloud pay-as-you-go plan. I attempted to install vs-mda-remote tools following a specific tutorial. MSDN Tutorial The tutorial mentioned that no admin access was required. Encountered errors while installing Homebrew dep ...

The ng-view DIV in Angular JS 1.x mysteriously vanishes

Currently, I am working on a project that involves angularJS and ASP.NET in Visual Studio 2013. However, I have encountered a frustrating issue where my DIV node for ng-view is being replaced with an ng-view comment without any errors appearing while testi ...

Using .NET Core 3.1 along with Vue, Axios, and incorporating the use of [ValidateAntiForgeryToken

I've spent the entire day working on this and researching as much as I can, but I have been unsuccessful in getting it to function. Despite comparing my implementation with the Microsoft documentation and various answers on Stack Overflow, none of th ...

Angular UI and Node backend causing CORS issues

Just diving into the world of node and could use a little assistance. Encountering this error message: Access to XMLHttpRequest at 'http://localhost:3000/api/auth/signin' from origin 'http://localhost:4200' has been blocked by CORS pol ...

Managing session IDs in PHP after a successful login to dynamically update the menu bar option from "login" to "logout"

On my website, you will find a menubar with five menus: HOME, DATA, FEEDBACK, ABOUT, and LOGIN. I want to be able to log in by clicking on the login menu (a jQuery modal window pops up for logging in), and after successfully logging in, I would like the ...

I am experiencing difficulties with my focusin not functioning properly for the input element that I added

I am working on a program that includes a dynamic table with the following structure: <table id="selectedItems"> </table> I plan to use jQuery to append elements to it like so: var i=0; $("#selectedItems").html(''); $("#sel ...

Conditionally rendered components in JavaScript may cause the element.contains method to return false

I'm currently working on a form selector component and my goal is to have the dropdown element close whenever a user clicks anywhere else on the screen. This component has the following design: export const FormSelect = ({ defaultText, disabled, ...

Sending various values from ASP.NET to a javascript function

I am currently attempting to pass multiple parameters (eventually 4 total) into a JavaScript function from my ASP.NET code behind. In the ASCX file, I have defined the function as follows: function ToggleReportOptions(filenameText, buttonText) { /*stuff ...

What is the best way to modify just a portion of the state in React?

Consider the following State object: const initialState = { data: { user: '', token: '', } } In the Reducer function: case 'DO_SOMETHING': return {...state, data: action.payload } If I make a shallow copy of th ...

Filtering pages using the Wordpress API version 2

Is there anyone who can help with the following: I am currently working on building an app in React and using Postman to filter pages. I have set up a Router that is supposed to filter the pages based on which button is clicked. I have experimented with a ...

"Delivering dynamic HTML content using React/Redux variables in the production environment

I am currently in the process of developing a React web application, and I have encountered an issue where a variable intended to store a schedule is being filled with the HTML content of the page when I build and serve the application. Interestingly, the ...

I am experiencing some difficulty with the GetServerDate using the JSON protocol in JQuery; it's

I am facing an issue while trying to execute a basic ajax call to fetch data from a file on a server. Even though I can access the file via the web browser and have diligently followed tutorials related to this topic, I have hit a dead end. Here is the sn ...

Display the hover effect for the current card when the mouse is over it

When the mouse hovers over a card, I want only that specific card to show a hover effect. Currently, when I hover over any card, all of them show the hover effect. Is there a way to achieve this in Vue Nuxtjs? Here's what I am trying to accomplish: ...