Learn the process of initializing object key/value pairs in Vuex to set their initial state

I'm encountering an issue in my application where I am trying to create an object to store key/value pairs for static texts and pass it to the initial state. However, I keep getting an error.

Here's a snippet from my helpers.js file:

    export const translation = Object.freeze({
        edit: 'Edit',
        please_select_text: 'Please select a row to edit',
        done: 'Done',
        role: 'Role',
});

Currently, I am importing this into my store module and passing it like this:

const defaultState = () => ({
       localized: translation. // This is how I am passing it
  
});

In my component, I'm attempting to access this state as follows:

{{localized.edit}}



...mapState(module_name, ['localized']),

However, I keep receiving errors. Can you help me understand how to properly use these static texts in my application?

Answer №1

This particular item doesn't appear to be suitable for inclusion in your store, as it is merely a helper constant and not a piece of state.

To incorporate it into your component, simply import the translation from '@/path/helpers.js' and then utilize 'translation.edit'.

Furthermore, if you did intend for it to be stored within your store, you are currently attempting to access it as 'translation.' instead of how it should be accessed: 'translation' (without the period).

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

State of buttons becoming active or inactive using jQuery

I'm encountering an issue with the jQuery code provided below: I have 3 buttons, which are defined as follows: <button class="btn btn-lg btn-primary" id="valider" data-actionname="appliquer" disabled>ok</button> <button class="btn bt ...

How to request permissions from a bot user in Discord.js version 14?

I need to verify my bot's permissions before it carries out a command. Previously, everything was functioning perfectly with this code: // Discord.js v13 if (interaction.guild.me.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES)) { interaction.re ...

I am looking to implement a Mouseover effect on my Canvas element using JavaScript

To create a mouseover effect only on a specific canvas location, I have developed the MousePosition function (as seen below). The commands for the mouseover effect should be implemented within the MouseOverButton function. However, despite my efforts, it ...

Identifying the class name of SVGAnimatedString

While working on creating an SVG map, I encountered an issue where the functions triggered by hovering over 'g' elements were not functioning as expected. In order to troubleshoot this problem, I decided to check for any issues with the class nam ...

Transform a React component from a regular function to an ES6 class

Recently delving into ES6 and React, I found myself navigating through various ways to write a React component. My journey began with "React.createClass," then transitioned to utilizing "extends React.Component" with ES6 classes syntax. While following a ...

The collaboration between vue-material and vee-validate is a seamless integration

I attempted to integrate vue-material and vee-validate together but encountered some issues. You can view the problematic setup in this fiddle The simplistic version without material design is functioning correctly, however, the material design implementa ...

Issues with Ajax arise once URL re-routing is activated

When loading content using AJAX and ASP.NET web-methods, the following code is used to trigger the Ajax request: var pageIndex = 1; var pageCount; $(window).scroll(function () { if ($(window).scrollTop() == $(document).height() - $(window).height()) ...

p5 - Syntax error: anticipated semicolon but received hour

Here is the code snippet in question: function setup() { createCanvas(500, 500); angleMode(DEGREES); } function draw() { background(0); translate(width/2, height/2); let hour = hour(); } There is an error on let hour = hour(); indicat ...

At what point is the JavaScript function expression triggered in this code snippet?

let express = require('express') let app = express(); app.use(express.static('static')); let server = app.listen(3000, function() { let port = server.address().port; console.log("The server has started on port", port); }); I ...

Collaborating on data through module federation

Currently, I am in the process of developing a Vue.js and TypeScript application using Vite. In addition, I am utilizing the vite-module-federation-plugin for sharing code across different applications. My main inquiry revolves around whether it is possibl ...

What is the best way to apply a JQuery UI Tooltip to a newly added element?

In my HTML file, I have included all the necessary JS and CSS files. Then I load a content page within it. Some of these content pages contain Usernames where I want to implement a tooltip feature. Here is an example of how they are structured: <user ...

Managing the event of a browser/tab being closed in React using Javascript

Currently, I have implemented the beforeunload event handler in order to detect when the user closes the browser. However, when this event is triggered, a popup appears with options for 'leave' and 'cancel'. Is it possible to capture th ...

Is there a way to instantiate a new object within the same for loop without replacing the ones created in previous iterations?

My current issue with this exercise is that as I convert the first nested array into an object, the iteration continues to the next nested array and ends up overwriting the object I just created. I'm wondering how I can instruct my code to stop itera ...

Encountering errors with CORS middleware when attempting to make a POST request to

I've developed a CORS middleware to prevent "CORS error" for all APIs. Here's my middleware code: $response = $next($request); $response->headers->set('Access-Control-Allow-Origin', '*'); $response->headers->set(&a ...

Can JavaScript be used to change the style and make a hidden input field vanish from view?

Currently, I am designing a table containing dates along with numerous hidden fields. print "<td"; { $dm=date('Y-m-d',strtotime("+".$i." days", strtotime($m))); print " class=\"overflow\" id=\"$a::$dm\" onclick=\" ...

How can I position a div in the center of a fullpage.js slide?

I'm currently utilizing the fullPage.js plugin sourced from this link: . I have successfully implemented vertical slides by using the following HTML code: <div class="section" id="section2"> <div class="slide" id="slide1"> ...

Displaying the result of a JavaScript function in a textarea

I've been working on getting this function to output to the textarea below. The current code functions correctly, but it displays the output on the whole page instead of in a text field. I know that the connection between the two is not properly estab ...

The ideal method to transmit reactive data effectively is through Vue.js

Implementing vue.js. I've created an authentication file (auth.js) that stores the user information upon detecting a change in authentication state. There are other sections of the website that need to update when the user information changes. What is ...

I am facing an issue with the clearTimeout function in my JavaScript code. Can anyone help

I am encountering some issues with the clearTimeout() function. The setTimeout() function is working as expected, but I want it to stop running when I close my notification. I'm not sure what is causing the problem in my function. After closing the ...

Sizing labels for responsive bar charts with chart.js

I'm encountering a problem with my bar chart created using chart.js - the responsive feature works well for some elements but not all. Specifically, the labels on my bar chart do not resize along with the window, resulting in a strange look at smaller ...