Vue has detected an error during rendering: "TypeError: state.actionInfo.find is not a function"

Using vue.js's cli, I created a basic data register application. The application utilizes lookback.js api with vue cli.

The application consists of three pages: show, add, and edit.

While the show and add pages function correctly, issues arise when attempting to edit existing data in the form. Two errors are generated for each modified label.

One example of a form element is "CMD_OPEN_GATE" in the database (postgresql).

Despite no errors appearing in the console upon page load, new input triggers the following errors:

[Vue warn]: Error in render: "TypeError: state.actionInfo.find is not a function"

TypeError: state.actionInfo.find is not a function

The values are obtained using Vuex, yet it remains unclear where the issue lies within the code.

Below are the relevant code snippets;

Form:

<h3>Action Info</h3>
<input v-model.trim="actionInfo" class="form-control form-group" type="text" @input="$v.actionName.$touch()">

Vuex store.js:

state: {
 actionInfo: [],
 .....
 .....
},
mutations: {
 actionInfoValue: (state, actionInfo) => {
  state.actionInfo = actionInfo
 },
},
getters: {
 getActionInfoByID (state) {
  return id => {
    return state.actionInfo.find(a => { return a.id === id })
  }
 }
}

Furthermore, the edit page contains the following codes.

methods: {
 actionInfoValue (val) {
  this.$store.commit('actionInfoValue', val)
 }
},
computed: {
 actionInfo: { // for action name
  get () {
    const i = this.$store.getters.getActionInfoByID(Number(this.$route.params.actionId))
    if (i) {
      return i.action
    }
    return ''
  },
  set (value) {
    this.$store.commit('actionInfoValue', value)
  }
 }
}

How can this problem be resolved? It seems like there may be an issue related to string-array compatibility. Despite researching extensively on stackoverflow, a solution has proven elusive.

Answer №1

I discovered the solution:

set (value) {
    this.$store.commit('actionInfoValueEdit', { id: Number(this.$route.params.actionId), action: value })
    // store.commit('addCustomer', { id: '2', name: 'User 2'})
  }

By modifying the set method as shown above, I was able to resolve the issue.

In addition, I implemented a new mutation for this specific scenario;

actionInfoValueEdit: (state, actionInfo) => {
  state.actionInfo.push(actionInfo)
},

The push function was utilized in this instance.

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

I encountered a problem with React Native while attempting to update the state with a new value

As I work on developing my app using react native and firebase, I encountered an issue with the error message TypeError: undefined is not an object (evaluating 'this.state.desativado.push') when attempting to click the + button. For the complete ...

Is there a way to cycle through an array with each click?

I am currently working on implementing a slider feature that enables users to navigate through different pieces of information by clicking on arrows. However, I have encountered an issue where one arrow works correctly (forward), but the other arrow does n ...

Importing WebAssembly dynamically can sometimes lead to complications with the order of execution

I am attempting to load a WASM library from another node js application, both utilizing webpack. Within the WASM library, I have the following code snippet exporting the functionality. export default import("./pkg") .then(s => { le ...

When I send data using axios, I receive the response in the config object instead of the data

Currently, my web app is being developed using NextJS NodeJS and Express. I have set up two servers running on localhost: one on port 3000 for Next and the other on port 9000 for Express. In the app, there is a form with two input fields where users can e ...

Issues encountered when attempting to send Jquery Ajax due to UTF-8 conflicts

I created a JavaScript script to send form data to my PHP backend. However, the text field was receiving it with incorrect encoding. Here is the meta tag on my website: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> Here&apo ...

Passing Data using Props in Vue 3 and Vue Router Leads to Invalid Parameters Alert

Currently, I am working on a project using Vue 3 and attempting to pass data between views via Vue Router. Specifically, I am aiming to transfer data from JobSelection.vue to Invoice.vue by utilizing router parameters. In my index.js file, I have defined ...

retrieving an element from a collection of objects

For a project utilizing the openweather api, I encountered fluctuating data based on the time of day it is viewed. My goal is to loop through the first 8 objects to identify a dt_txt value of 12:00:00. Once found, I intend to store this result in a variabl ...

challenges with Next.js dynamic routing when dealing with spaces

I am facing an issue with accessing dynamic routes using a product name from my API when the name contains spaces. However, I can access the routes without any problem if the product name is just a single word. utils/api.js export async function getProduc ...

jQuery image resizing for elements

I have successfully adjusted the images in the gallery to display one per row for horizontal orientation and two per row for vertical orientation. Now, I am facing a challenge in making the images scalable so they can resize dynamically with the window. A ...

creating a custom mongoose model using aggregation and filtering

My Review model includes two fields, product and rating. I want to calculate the total rating for a specific product and then find the average by dividing that total by 5. const mongoose = require('mongoose'); const ReviewSchema = mongoose.Sche ...

Adding @submit.prevent conditionally to a form in Vue.js

I'm attempting to employ conditional prevention of HTML form submission using @submit.prevent. I have a simplified generic form model structured like this: <v-form v-model="valid"> <div> <div v-for="(field, i) i ...

Transferring SQL server dates to jQuery Calendar through AJAX communication

I am currently working on implementing a jQuery calendar example, and I want to load the dates from my SQL database instead of using hardcoded values. I am considering using Ajax post to send a request to my web method and retrieve the data. However, I am ...

An unusual html element

During a recent exploration of a website's code using the inspect tool, I stumbled upon a tag that was completely unfamiliar to me. <gblockquote></gblockquote> I've come across a blockquote before, but never a gblockquote. Interest ...

Believing in false promises as true is what the statement assumes

I'm working on authentication for my app and encountered the following code: const ttt = currentUser.changedPasswordAfter(decoded.iat); console.log(ttt); if (ttt) { console.log('if thinks ttt is true'); The changedPasswordAfter fu ...

JavaScript - Matching overlapping time intervals

Struggling to develop a custom filter using Javascript, I aim to determine if two time ranges in millisecond getTime() format match. The first time range is retrieved from an object while the second comes from user input for filtering. Currently, my code c ...

What is the process for specifying the Charts within the script?

I've recently started working with Vue.js and I'm looking to create a chart in my application. To begin, I need to install the charts library into the directory using the following command: npm install chart.js --save Here is the code snippet f ...

Visualizing Data with Flot.js - A Comprehensive Guide

Does anyone know how to organize values in a flot histogram by day, merging them into one bar per day? I've been searching for a solution but can't seem to find one. __ If you have any ideas, please share! ...

Is it possible to implement a custom sign-in form for AWS Cognito?

Is it possible to replace the AWS Cognito hosted UI with a custom form in my Next.js app that utilizes AWS Cognito for authentication? import { Domain } from "@material-ui/icons"; import NextAuth from "next-auth"; import Providers fro ...

Tips for delaying the execution of numerous ajax success callbacks?

In my JavaScript code, I am facing the following situation: call_A(success_A) call_B(success_B) function call_A(success){ // make ajax request success(result) } function call_B(success){ //make ajax request success(result) } function success_A(){ ...

Can someone guide me on how to use contract.on() in ethers.js to listen to events from a smart contract in a node.js application?

I've been working on a node.js application using ethers.js to listen to events emitted from the USDT contract Transfer function. However, when I run the script, it exits quickly without displaying the event logs as expected. I'm unsure of what st ...