How can attributes be passed to a Vue JS computed property getter and setter?

Attempting to utilize computed properties for binding input fields with the Vuex Store has presented some challenges. Each Data Stream in my application has dynamic input fields, managed through the admin section. I need to allow users to select a specific data stream, after which the corresponding inputs should be displayed based on API response.

I have made an attempt to achieve this functionality, but I've hit a roadblock. Computed properties (getters) do not accept attributes, making it impossible to specify which data the vuex getter should return.

Below is the code snippet that I've been using. Is there another approach to achieve the same outcome?

The versions I am currently working with are:

  • vue - 2.6.1
  • vuex - 3.6.2
  • vuetify - 2.5.6

Vue JS Component - Input Fields

<v-text-field
    :key="input_index"
    v-model="data_stream_inputs[ds_index][input_index]"
    :label="input.name"
    :placeholder="input.placeholder"
></v-text-field>

Computed Properties (Issue with functionality)

computed: {
    data_stream_inputs: {
        get() {
            return this.$store.getters['ActivateAudienceStore/getDataStreamInputByIndex'],
        set(value) {
            this.$store.commit('ActivateAudienceStore/SET_DATASTREAM_INPUT_BY_INDEX', value)
        }
    }
}

Getter Function

export const getDataStreamInputByIndex = (state) => (payload) => {
    return state.data_delivery.datastreams[payload.data_stream].inputs[payload.index]
}

Answer №1

data_stream_inputs should be transformed into a function to accept arguments and used in the format

data_stream_inputs({ index: index1 })[index2]
. This setup may not work seamlessly with a writable computed property.

v-model does not necessarily need to be utilized in situations where it is not intuitive, as it can be broken down. For instance, in Vue 2:

<v-text-field
    :value="$store.getters['someGetter']({ index: index1 })[index2]"
    @update:value="$store.commit('someMutation', $event)"
    ...

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

Aligning Page to a Specific Element Without Changing the DOM or Utilizing References

My goal is to easily scroll to a specific element using #: <a href="#element">Element</a> <div name="element" /> While this method works effectively, it always takes me to the top of the element. I would prefer to have the element cent ...

Receiving an ambiguous message from the meteor subscriptions

New to using Meteor, I am trying to create a registration form with Meteor. I am facing some challenges with the `findOne` and `subscribe/publish` functions. Here is my `collection.js` file: User_Customer = new Meteor.Collection("USER_CUSTOMER"); Custome ...

How to verify changes in session variable using PHP and AJAX

Hey there! I'm looking for a way to continually monitor changes in a session variable within PHP. Let's say the session variable "x" starts off with a value of "1" and then, after five seconds, it changes to "2". This session variable "x" is up ...

"Using Node.js Express 4.4 to efficiently upload files and store them in a dynamically

Looking for recommendations on the most efficient method to upload a file in node.js using express 4.4.1 and save it to a dynamically created directory? For example, like this: /uploads/john/image.png, uploads/mike/2.png ...

Developing a dynamic user interface using an Angular framework and populating it with

I am currently learning Angular (version 1) and facing an issue with my layout. I need to dynamically change the navigation based on the type of user that is logged in. To achieve this, I make an API request when the page loads to fetch the user object dat ...

``Emerging Challenge in React: Ensuring Responsive Design with Fixed Positioning

I'm currently encountering a challenge with my React application. I've developed a website using React that includes a component named CartMenu, which is integrated within another component called Products. The issue arises when I utilize the de ...

Error: The method _firestore.default.initializeApp is not defined as a function

I am encountering an issue in my app where "_firestore.default.initializeApp" is not recognized as a function while evaluating src/screens/Login.js, src/appNavigator.js, and App.js. I have already ensured that I have added the firebaseconfig and connected ...

GraphQL query must receive an object for the Mongo filter, but instead, it received a string

Is there a way to pass a filter option to MongoDB using GraphQL? I attempted to do it in a certain way, but encountered an error that stated: "message": "Parameter \"filter\" to find() must be an object, got {email: "<a href="/cdn-cgi/l/email ...

Tips for adding animation to a React state value change triggered by an input

In my React application, I have a form with multiple fields that each contain a text input and a range input. Currently, both inputs share the same state value and onChange function to keep them synchronized. However, I would like to add an animation effe ...

Swapping out the JSON data from the API with HTML content within the Vue.js application

I am currently working on a project involving Vite+Vue.js where I need to import data from a headless-cms Wordpress using REST API and JSON. The goal is to display the titles and content of the posts, including images when they appear. However, I have enco ...

Unable to adjust offset/repeat of texture being utilized as alphaMap

demo: the alphaTexture is being modified in its offset with each render. When used as a "map" property, the offset changes, but when used as an "alphaMap" it remains static. This issue arises with the second mesh's alphaMap. relevant code from demo ...

Generate a collection of div elements as child nodes

I'm working on a project where I have multiple rows with input fields. My goal is to create an array for each row that contains the values of the inputs. For example, if I have 3 rows and the values of 'input1' are 1, 'input2' are ...

Is it possible to incorporate dynamic variables into the directives of a nested loop? Plus, thoughts on how to properly declare variables in a node.js environment

Question Explanation (Zamka): <----------------------------------------------------------------------------------------------------------> Input Example: 100 500 12 1st Line: represents the left bound (L) 2nd Line: represents the right bound ...

A guide on sharing an express.js response object with a different module

In my server.js file, I am attempting to pass an Express response object to a different module. Here is how I have implemented it: const room = require('../controller/rooms_controller') app.post('/rooms', function(req, res){ var na ...

Creating a basic bar chart using NVD3 with X and Y axes in AngularJS

I'm currently utilizing the nvd3.js plugin within my angular-js application. I have a straightforward task of creating a bar chart, where bars represent months along the x-axis and revenue values on the y-axis. My goal is to accomplish this using the ...

What aspects of MongoDB security am I overlooking?

Is it a secure way to connect to Mongo DB by using Node JS, Mongo DB, and Express? Could someone provide an explanation of this code in terms of security? === Many tutorials often only show... var mongoClient = new MongoClient(new Server('localhos ...

What are the steps to configure Bootstrap for optimal performance?

Here is the code snippet: <template lang="pug"> b-container b-row b-col h1 strong LICOTA® — ПРОФЕССИОНАЛЬНЫЙ ИНСТРУМЕНТ ВЫСШЕГО КЛАССА ДЛЯ АВТОСЕРВИСОВ И ПРОМ ...

Switch up the URL and redirect by employing jQuery

Looking for a solution in jQuery to redirect based on user input? <form id="abc"> <input type="text" id="txt" /> </form> If you want to redirect to a URL constructed from the value of the text box, you can try this: var temp = $("#tx ...

I'm having trouble getting the JADE tag to render in Express script. Can anyone help me

I am trying to include client-side script in my JADE template and so far I have: extends layout script. function collect_data() { var transitions = {}; $( ":checkbox:checked" ).each(function (index, element) { //// some code ...

The Material UI slider vanishes the moment I drag it towards the initial element

After moving the Material UI Slider to the initial position, it suddenly vanishes. via GIPHY I've spent 5 hours attempting to locate the source of the issue but have not had any success. ...