The use of props within components is broken in the interface of Nuxt and Vuejs

I am having trouble accessing an object's interface within a component using props.

Is there anyone who can provide guidance on how to resolve this issue?

PortariaInterface

define interface PortariaInterface {
  entryDate: string
  nfe?: {
    number: string
}

Template

<Form :data="data" />

Ts

import {PortariaInterface} from '@/models/PortariaInterface'
import { Form } from '@/components/portaria'

export default Vue.extend({
  name: 'HomePage',
  components: { Form },
  layout: 'portaria',
  data() {
    return {
      data: {} as PortariaInterface
    }
  }
})

Component

<el-col :xs="24" :sm="8" :md="8" :lg="6" :xl="4">
        <el-form-item label="NFe Number">
          <el-input v-model="data.nfe?.number"></el-input>
        </el-form-item>
      </el-col>

export default Vue.extend({
  name: 'Form',
  props: ['data']
})

Error

TypeError: Cannot read properties of undefined (reading 'number')

Answer №1

In this particular scenario, you have two bindings that need to be handled using the v-model directive on your Formulario component like so:

 <Formulario v-model="formulario" />

Within this component, bind the input using the value and @input event:

<el-col :xs="24" :sm="8" :md="8" :lg="6" :xl="4">
        <el-form-item label="Número NFe">
          <el-input :value="numero" @input="onInput"></el-input>
        </el-form-item>
      </el-col>

export default Vue.extend({
  name: 'Formulario',
  props: ['value'],
  computed:{
   numero(){
     return this.value.nfe?.numero
   }

 },
 methods:{
  onInput(val){
    this.$emit('input',val)
  }
}
})

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

The Vuejs component makes a duplicate API request

Currently, I am in the process of developing a To-do Application using Vuejs, Expressjs, and Mongodb. I have successfully implemented the New Component with a separate link. However, I encountered an issue when importing the New Component into the Root Co ...

What is the best way to ensure that GCM push notifications are still received even when the app is closed or the

Currently, I'm in the process of developing an application using Ionic 2 that requires push notifications to be received. In certain scenarios, such as when the app is force-stopped on Android or when the device is turned off, push notifications are ...

Encountered difficulties in deploying functions on Firebase Cloud Functions

While developing the Firebase Cloud Functions, I organized the files based on each function. Unfortunately, numerous errors occurred during deployment. Error [debug] [2022-07-19T14:36:17.677Z] <<< [apiv2][body] GET https://us.gcr.io/v2/xxxxxx/gcf ...

Exiting a void method in JavaScript/Typescript using the return or break statement

I find myself dealing with a complex method in Typescript that contains multiple if else if else constructs. It's a void method, and I'm wondering how I can exit the method based on a specific if condition without having to execute the remaining ...

Deploy quickly using Vite on Azure Devops

We are facing a challenge while deploying our new Vite +Vue3 application to the server. The issue lies with our outdated yaml file, which still includes a "--dest" option from our previous Vue 2 CLI deployment. Is there anyone familiar with how to specify ...

What is causing my requests to appear in the network tab of devtools while utilizing Nuxt.js (SSR)?

Currently, I am using nuxt version 3.11.1 and facing an issue where even though I try to send my server-side requests, I do not see them in the network tab. This is making me question if the requests are being sent correctly. To handle sending requests, I ...

Creating an interface that accurately infers the correct type based on the context

I have an example below of what I aim to achieve. My goal is to start with an empty list of DbTransactInput and then add objects to the array. I experimented with mapped types to ensure that the "Items" in the "Put" property infer the correct data type, w ...

Vue js throws a maximum call stack error when updating a Chart component

I have successfully created a line chart using the Chart.js 3.5 library. The chart is responsive, all animations are working fine too. I am currently facing an issue where I am attempting to update the data from a parent component and trigger a chart updat ...

Performing function in Vue.js when a change occurs

I recently started developing a Vue.js component that includes an input field for users to request a specific credit amount. My current goal is to create a function that will log the input amount to the console in real-time as it's being typed. Ultima ...

Exploring methods in Firebase Cloud Functions to retrieve and modify values

I'm currently attempting to retrieve a value from a specific location in my database, add 1 to it, and then update it back. However, I keep encountering various errors, with the most recent being: TypeError: Cannot read property 'update' of ...

The reference to Vuex's this.$store is not defined

I am currently learning Vue with Vux and Vuetify. I have successfully installed it using Vue CLI. Following the documentation, I attempted to access the store but encountered an 'undefined' error for this.$storage. Here is the code snippet from ...

The condition of the variable not being bound

<button id="btn1"> Button 1 </button> <button id="btn2" v-if="state == 2"> Button 2 </button> export default { data() { return { emailPreferences: { isLoading: false ...

What is the best way for me to examine [...more] closely?

import * as Joi from 'joi'; import 'joi-extract-type'; const schema = { aaaaaaa: Joi.number() .integer() .positive() .allow(null), bbbbbb: Joi.number() .integer() .positive() .all ...

Inquired about the installation of Typescript in the Docker image building process despite it already being installed

I am in the process of creating a docker image for a Next.js/React application that utilizes Typescript. Typescript is installed and I can successfully generate a local build without docker. However, during the docker image creation, I encounter the foll ...

Step-by-step guide on fetching blog posts from a Ghost blog by utilizing the API in a Vue cli project

I'm currently working on my Vue cli project and I am trying to showcase all the posts from a Ghost blog using the API. Unfortunately, the example provided on the page is for a nuxt project. Once we have called the dependencies and authenticated with ...

Encountered a syntax error while running the Vue2 serve command: Unexpected token

I recently developed a test app using vue-diagram-editor from https://github.com/max-kut/vue-diagram-editor. Everything was working fine with the test app, so I decided to install it into my main Vue app that was running smoothly before. $ npm install --s ...

VueJS - oops! Looks like we hit a limit with the call stack size. The error occurred at VueComponent.onFocusin

I imported a dialog component into my Document.vue file and encountered an error when attempting to add the dialog. This issue was resolved when I removed a specific element from my code. Can someone provide assistance? Here is the added code: <templat ...

What is the best approach for informing Vue about the location of my backend when accessing it through a network IP rather than localhost?

I have a Vue setup on localhost:8080 as a single-page application, and a Laravel backend running on localhost:80 as a REST API. Everything works perfectly fine on my computer. However, when I try to access my localhost web app on my phone using the networ ...

Utilizing Vue.js keep-alive to optimize performance by excluding Ionic components

The components from a specific library are not compatible with Vue.js' keep-alive feature. I have attempted to exclude them using exclude="/^ion-*./", but it has not been successful. These components do not have a designated name. Is there a way to p ...

React-querybuilder experiencing issues with validator functionality

While utilizing the react-querybuilder, I have encountered an issue with field validation not functioning correctly. Upon reviewing this StackBlitz, it appears that when clicking on Rule and checking all fields, there are no errors present. export const fi ...