Vue3 with Typescript encounters an issue when attempting to apply v-model to a textarea element

Trying to implement v-model on a tag within my Vue component, I encountered the following error that is puzzling me:

The 'textInput' property does not exist on the type '{ $: ComponentInternalInstance; $data: {}; $props: Partial<{}> & Omit<Readonly<ExtractPropTypes<{}>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>;

The Component in question:

<template>
  <h1>Check how often a word is repeated in your text:</h1>
  <textarea
    name="userInput"
    id="userInput"
    cols="30"
    rows="10"
    v-model="textInput"
  ></textarea>

  <CheckButton />
</template>

<script lang="ts">
import { defineComponent } from "vue";
import CheckButton from "./CheckButton.vue";

export default defineComponent({
  name: "FrequencyBox",
  components: {
    CheckButton,
  },
});
</script>

<style></style>

Answer №1

To create reactive functionality for the textInput element, you can use the ref method and return it as shown below:

Take a look at the code snippet provided:

const { ref } = Vue
const app = Vue.createApp({
  el: "#demo",
  setup() {
    const textInput = ref(null)
    return { textInput }
  }
})
app.mount('#demo')
<script src="https://unpkg.com/vue@3"></script>
<div id="demo">
  <h3>Check how often a word is repeated in your text:</h3>
  <textarea
    name="userInput"
    id="userInput"
    cols="30"
    rows="5"
    v-model="textInput"
  ></textarea>
  {{ textInput }}
</div>

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

What is the reason for user.id being set as a 'string' by default?

Currently, I am in the process of creating a Next Auth system using TypeScript, and I have encountered a type issue related to the 'user.id' data. This error is specifically happening in the callbacks section. The types of 'user.id' ar ...

Bar chart in Chart.js becomes crowded and illegible on smaller screens due to overlapping bars

Hello there! I've encountered an issue where the bar chart overlaps when the screen width is too low. It seems to be related to the maintainAspectRatio property, which I set to false because I wanted the charts to shrink only in width, not in both axe ...

I am unable to retrieve the value stored within a function

Below is the code snippet : let namesList = ref([]); const GetFormData = (payload) => { return new Promise((resolve, reject) => { api .get("api.php", { params: { search: payload } }) .then((response) => { data. ...

Ways to generate an Angular 7 component

Seeking guidance on creating an angular 7 component. I have forked a jsFiddle at this link: https://jsfiddle.net/gauravshrestha/fdxsywLv/. The chart in the fiddle allows data points to be dragged up and down. My goal is to convert this into a component whe ...

Linking together observables to handle the response received from the PrimeNG confirmation service

Currently, I am utilizing the confirm.service from PrimeNG in my application. My goal is to display an array of messages to the user with only one message shown at a time along with an Accept button. However, my current code is only displaying the last me ...

V-Stepper Slot Header in Vuetify 3 - Elevate Your Stepper

In the realm of creating a v-stepper in Vuetify 3, there exist two primary methods. One can either utilize the properties or delve into the template/slots. Personally, I encountered an issue with the properties method where the transition got all jumbled ...

Is there a way to modify an image that has been dynamically inserted in an Angular application?

I'm facing an issue with dynamically added input files in Angular. Whenever I upload a file, it changes all the images of the input files instead of just the one I want to target. How can I resolve this problem? Please help. images = [ {url: &ap ...

Sending a string of HTML elements to a Vue custom directive is causing problems with the eslint code analysis

I have developed two custom Vue directives to add an HTML element before or after another element. I provide an HTML string to the element where I apply the directive, but I am encountering an error in VS Code: Parsing error: unexpected-character-in-a ...

Issues with user-generated input not properly functioning within a react form hook

After following the example provided here, I created a custom input component: Input.tsx import React from "react"; export default function Input({label, name, onChange, onBlur, ref}:any) { return ( <> <label htmlF ...

Tips for keeping your attention on the latest HTML element

Welcome to my HTML Template. <div cdkDropList class="document-columns__list list" (cdkDropListDropped)="dragDrop($event)" > <div cdkDrag class="list__box" ...

Adding numerous objects to a Vuex store using mutations

I am currently working with the following store setup: import Vue from 'vue' import Vuex from 'vuex' import axios from 'axios' Vue.use(Vuex) export default new Vuex.Store({ plugins: [createPersistedState()], state: { ...

Pairing Keycloak with a Vue SPA as the client, utilizing Spring Cloud Gateway as the resource server, and deploying Spring Boot Microservices

I am looking to implement my project in a certain way: https://i.sstatic.net/Efpo4.png Everything seems to be working fine except for Vue (axios) returning a 401 error when trying to request data from a microservice through a gateway. Even though I have ...

Unexpected outcome when mocking Vuex getters in unit testing

I've been delving into writing unit tests for VueJS components and have been utilizing this article as a guide for testing components that rely on the Vuex store. Let's take a closer look at the component in question: <!-- COMPONENT --> & ...

Implementing an Ant Design Form field for an array of objects

Is it possible to edit an entity with a one-to-many relation? { id: 1, title: 'Title', tags: [ { id: 1 }, { id: 2 }, ], } Here is the code snippet: <Form.Item name={["tags", "id"]} > < ...

The value binding for input elements in Angular 4 remains static and does not reflect changes in the UI

Struggling with binding input to a value in angular 4? Take for example [value]="inputFrom". Sometimes it updates when I change inputFrom, other times it doesn't. How can I ensure the input always changes whenever inputFrom changes, not sporadically? ...

VueJS encountered an insecure XMLHttpRequest endpoint during the request

I am currently working on a project that consists of a VueJs app with a Laravel backend serving as the API. While testing the app locally, everything works smoothly with the Https protocol. However, upon deploying it to the production server, I encountere ...

Angular 7: An unexpected error occurred when trying to inject TripsMenu into MenuWidgetComponent in AppModule

Encountering an issue in angular 7, where I am trying to inject my MenuWidgetComponent in the home component. I have imported it in the widget component and exported it via index.ts. However, the following error persists: I searched online but couldn&apos ...

When trying to use `slug.current` in the link href(`/product/${slug.current}`), it seems to be undefined. However, when I try to log it to the console, it is displaying correctly

import React from 'react'; import Link from 'next/link'; import { urlFor } from '../lib/clients'; const Product = ({ product: { image, name, slug, price } }) => { return ( <div> <Link href={`/product/ ...

The specified property 'XYZ' is not found in the type 'Readonly<{ children?: ReactNode; }> & Readonly<{}>'

Whenever I try to access .props in RecipeList.js and Recipe.js, a syntax error occurs. Below is the code snippet for Recipe.js: import React, {Component} from 'react'; import "./Recipe.css"; class Recipe extends Component { // pr ...

Analyzing a sizable JSON file serving as the data source for a PostgreSQL database

Currently, I am working on a Next.js project that involves a large JSON file (~65,000 lines) serving as data for a Prisma Postgres database. The structure of the file includes entries like the following: [ { "NativeClass": "class-name", "Classes" ...