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).

https://i.sstatic.net/nKuru.png

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

Is there a method I can utilize to ensure functionality within Google Apps Script?

I encountered an issue when using innerHTML instead of getBody() and I am looking for assistance with debugging on apps-script as mine is not functioning properly. function findText(findme,colour,desc,rule_name) { var body = DocumentApp.getActiveDocum ...

Localizing HTML number input values is not functioning properly

When using an HTML number field, I encountered the following error: The specified value "101,5" is not a valid number. The value must match the regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)? I am trying to co ...

Issues with Angular route links not functioning correctly when using an Array of objects

After hard coding some routerLinks into my application and witnessing smooth functionality, I decided to explore a different approach: View: <ul class="list navbar-nav"></ul> Ts.file public links = [ { name: "Home&quo ...

When the function is called, it will return the global `this

Attempting to bind the user object as 'this' and default time as the first parameter utilizing the function.call method let user = { name:'rifat', txt (time, msg){ console.log('['+time+ '] '+ this.name+ &apo ...

Switching between languages dynamically with Angular JS using $translateProvider and JSON files

I currently have a collection consisting of 6 different JSON files. en.json es.json fr.json it.json ja.json zh.json An illustration of the data present in each file is as follows (in this instance, considering en.json): { "SomeText": "Test in Englis ...

Issue encountered while attempting to load several google charts simultaneously

What do I need? I am in need of two Google charts, one on each tab of the website as shown in the screenshot below: Tabs What seems to be the issue? The second chart is not loading properly and showing mixed information. This can be observed in the scre ...

Why is webpack attempting to package up my testing files?

In my project, I have two main directories: "src" and "specs". The webpack configuration entrypoint is set to a file within the src directory. Additionally, the context of the webpack config is also set to the src directory. There is a postinstall hook in ...

The routes may be the same in both React Router Dom v6, but each one leads to a different

I am struggling to set up different routes for navigation and I'm not sure how to do it. Here is what I have attempted so far: const router = createBrowserRouter( createRoutesFromElements( <> <Route path="/" element={<NavB ...

What is the best way to successfully implement multiple post requests using Django and Ajax on a single webpage?

After spending the entire day struggling with this issue, I am still unable to make any progress. Let me explain my predicament. In my Django form, I have two fields: redirect_from and redirect_to. The form contains two buttons: Validate and Save. Initial ...

Turn off the extra space inserted by DataTables

Help needed with centering table header text. <table class="table table-bordered table-hover center-all" id="dataTable"> <thead> <tr> <th scope="col" style="text-align: center">Nam ...

The datepicker is refusing to update the date format

I've been attempting to adjust the date format for my datepicker, but it refuses to change. Below is the code I'm using: $(document).ready(function() { $('#dateselect').datepicker({ format: 'dd/mm/yyyy', o ...

Retrieve an image using screen resolution parameters [using only HTML]

During a recent interview, the interviewer posed an interesting question regarding 2 images: There is one large resolution image that needs to be displayed on laptops and desktops. There is also a small image that should only be shown on mobile devices. ...

A JQuery function linked to the click event of the body element triggers another click event right away

$().ready(function(){ $("#move-to").click(function(){ $("body").bind("click",function(){ alert("foo"); }); }); }); Why do I receive an alert message of "foo" immediately after clicking on "move-to"? When I bind the " ...

Exploring Several Images and Videos in Angular

I'm experiencing a challenge with displaying multiple images and videos in my Angular application. To differentiate between the two types of files, I use the "format" variable. Check out Stackblitz export class AppComponent { urls; format; on ...

Utilizing API calls within a loop using AngularJS

I need to execute a series of APIs in a loop, but I want the second loop to start only after receiving the result from the last API call in the first loop. How can I achieve this? for(var i=0; i<array.length; i++ ) service.getfunction(array[i]).t ...

JavaScript class syntax allows for the definition of inherited instance fields

In the code snippet below, I have implemented a way to define a prototype with a simple property that can be inherited by objects using the prototype: const SCXMLState = Object.setPrototypeOf( Object.defineProperties({ addChild() { } isStat ...

What is the method for utilizing string interpolation in Angular/Typescript in order to retrieve a value from a variable?

I have a variable called demoVars, which is an array of objects with properties var1, var2, and var3. In my component class, I have a variable named selectedVar that holds the name of one of these properties: var1, var2, or var3. I want to dynamically pu ...

What could be causing npm to not recognize my module in the "require" statement?

Currently, I am in the process of developing an npm module and conducting tests before making it available to the public. The method I am following is outlined in a blog post found at this link. However, I am encountering difficulties when trying to requir ...

Transmitting information from JavaScript to a PHP script

I am currently using a function that grabs text from a PHP file on our server and inserts it into an HTML page. However, I now need to modify this function in order to SEND data (specifically a couple of JavaScript variables) to the PHP file instead of si ...

Managing touchEvents in Vue: A comprehensive guide

Is it possible to manage touch events in Vue3 without using an external library? I am trying to make an element draggable (drag and drop to another location) with touch input. The elements are generated using v-for. I was able to implement mouse control w ...