Sending property value to computed properties within a component

Is it considered a best practice to utilize a prop value within a computed property function of a component? If so, how can I construct the return statement using this prop?

Carousel.vue

props: [
  'source',
],
computed: {
   items () {
     return this.$store.state.(prop value source here).list
   }
}

store/categorya.js (the same for categoryb and categoryc)

import categorya from '(...)'
export const state = () => ({
  list: categorya
})

Update

Index.vue

carousel(source="categorya")
carousel(source="categoryb")
carousel(source="categoryc")

Answer №1

This answer provides a solution for accessing data from Vuex state. If the source indicates a module name in Vuex, bracket notation can be used:

computed: {
  items () {
    return this.$store.state[this.source].list
  }
}

AFTER EDITING

Even after editing, the question remains somewhat unclear. However, if there are no modules and list is directly under the root state, you can simply use:

computed: {
  items () {
    return this.$store.state.list
  }
}

Regardless of how list is initially defined by an import named categorya, the key thing to remember is that it's still the only available state property with the name list.

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

Working with AngularJS $resource: including an array element in paramDefaults

I'm currently working with the twitch.tv API and utilizing the Angular $resource factory. My goal is to access the endpoint: GET /channels/:channel. What I want to achieve is to retrieve the channel for each element within an array. I attempted using ...

What is the best way to make a request to the deployed API on Vercel?

Here is the structure of my files: root client index.js package-lock.json package.json routes.js Upon sending a request to my API, I receive a status code of 200 but an error message stating "You need to enable JavaScript to run this app." Both ...

Explore the properties within an array of objects through iteration

Here is the array I'm working with: const myArray = [{ id: 1, isSet: true }, { id: 2, isSet: false }, ...]; I only need to iterate over the isSet properties of the objects, ignoring all other properties. Initially, I attempted the following solution ...

Exploring Vue 3 and Pinia: Achieving Reactivity in Stored Values

Currently, I am working on a project using Vue 3 with the Composition API and Pinia. Within my application, I have an auth store that retrieves the default email and password values from the store. import { useAuthStore } from "stores/auth"; const authSto ...

Items seem to vanish into thin air and become immovable when attempting to relocate them

I am attempting to create a unique grid layout with 3x3 dimensions, where each grid item represents a fragment of a single image. These items should have the capability to be dragged and dropped inside another 3x3 grid, in any desired sequence. I have hit ...

JS Implementing a real-time reactive data dynamic bar chart graph in Vue3

Objective My current project involves using Vue3 with the Composition API. I am looking to incorporate real-time data streaming into a chart or graph, aiming for a smooth update rate of 60 frames per second. Additionally, there may be multiple streams and ...

Prevent the resizing of my website on iOS devices using HTML and CSS

I'm encountering an issue with a website I developed that seems to be resizable on certain iOS devices, including the new iPhone X. I haven't been able to replicate this behavior on other standard websites. Perhaps there's a simple CSS solut ...

Utilize jQuery and JavaScript dynamically in an HTML document on iOS devices

Having some trouble with this code snippet and getting it to work as intended. - (void)viewDidLoad { [super viewDidLoad]; _webview.delegate = self; [_webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBun ...

Having trouble displaying the output on my console using Node.js

Hey there, I'm new to this community and also new to the world of nodejs technology. I have encountered a problem that may seem minor to you but is quite big for me. Here's what's going on: In my code snippet, I want a user to input 3 value ...

Tips for obtaining the combined outcome of multiple arrays (3 to 5 arrays) in JavaScript

How can we transform an array of objects with nested arrays into a new array of objects with mixed values? Consider the following input: var all = [ { name: "size", value: [20, 10, 5], }, { name: "color", value: [ ...

Identifying the initial object with a duplicate property within an array of objects using JavaScript

In my code, I have an array structured like this: var myArray = [ {id: 1, entry_id: 1, name: 'test', email: 'email1'}, {id: 2, entry_id: 1, name: 'test', email: 'email2'}, {id: 3, entry_id: 2, name: &ap ...

Question about sending multiple Axios POST requests with parameters

I'm new to Stack Overflow and seeking help with a specific issue on my Rails backend and Vue.js frontend website. The challenge I'm facing involves making two POST requests simultaneously when the submit button is clicked. My "Trips" controller ...

Issue with Bootstrap Modal Tabs not functioning

CODE <!-- Unique Modal Code --> <div class="modal fade" id="uniqueModal" tabindex="-1" role="dialog" aria-labelledby="uniqueLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="m ...

What causes the data to flicker between the old and new values when the state is updated in ReactJS?

Currently, I am developing a single-page application that fetches data from the Star Wars API. In the character section of the project, the goal is to display characters per page with the ability to navigate to the next or previous pages by clicking on but ...

Enveloping an immediate search within a JavaScript throttle function

Below is a code snippet for a cloud tag (Goat1000) with an instant query. The query part should be enclosed within the throttle function from the underscore.js library to prevent server crashes. <script src="underscore-min.js"></script> &l ...

It seems that JavaScript is unable to detect newly added elements following an AJAX request

One issue I'm facing is that when an element loads data based on a clicked block, all javascript functionalities break. Currently, using Ajax, I load an entire PHP file into my index after sending a variable to it. For example: If Block 1 is clicked ...

How can I deactivate a Material UI button after it has been clicked once?

Looking to make a button disabled after one click in my React project that utilizes the MUI CSS framework. How can I achieve this functionality? <Button variant="contained" onClick={()=>handleAdd(course)} disabled={isDisabled} > ...

Issues with $routeProvider in a web page hosted by Express.js

As I embark on creating my very first Express.js/Angular application, I'm encountering a challenge with the $routeProvider in the page served by the Express.js application. Let's take a look at the server.js: var express = require('express& ...

Several radial progress charts in JavaScript

While attempting to recreate and update this chart, I successfully created a separate chart but encountered difficulties with achieving the second progress. The secondary chart <div id="radial-progress-vha"> <div class="circle-vha ...

Troubleshooting issues with Ajax and Jena

Whenever I attempt to utilize AJAX to call Jena in my servlet, I encounter this error: java.lang.ClassNotFoundException: com.hp.hpl.jena.sparql.core.Prologue at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516) at org.apa ...