Issue with Vue mounting causing component to not receive updated values

Below is the Vue main file I'm working with:

export default {
    name: 'app',
    components: {
        FormSelector,
    },
    data () {
        return {
            headerInfo: {
                issue: '',
                model: 'model-1'
            }
        }
    },
    mounted () {
        this.headerInfo = JSON.parse(localStorage.getItem('header'))
    },
    methods: {
        selectModel (model) {
            this.headerInfo.model = model
        },
    }
}

Here's how I call the component within my code:

<FormSelector @select="selectModel" v-bind:model="headerInfo.model"/>

The script for the component looks like this:

export default {
    name: 'FormSelector',
    props: ['model'],
    data () {
        return {
            select: this.model,
        }
    },
    methods: {
        changeModel (e) {
            const model = (e.target.value)
            this.$emit('select', model)
        }
    }
}

I'm wondering how to update the value of select data when the mounted cycle loads headerInfo data from localStorage.

Currently, only the headerInfo data in the main file gets changed and not the select data.

Answer №1

Modify the mounted function to include async and await syntax.

async mounted () {
  this.userInfo = await JSON.parse(localStorage.getItem('user'))
}

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

Utilize Angular2 data binding to assign dynamic IDs

Here is the JavaScript code fragment: this.items = [ {name: 'Amsterdam1', id: '1'}, {name: 'Amsterdam2', id: '2'}, {name: 'Amsterdam3', id: '3'} ]; T ...

Integrate SVG directly into the three.js module to eliminate the need for an additional HTTP request

Currently, I am developing a small website that features a simple 3D animation. The model is extruded from an SVG file loaded using SVGLoader. My goal is to enhance the loading speed by including the SVG as text in my threejs code, eliminating the need for ...

UI Router: Easily navigate to a specific route by entering the URL directly

I encountered what I thought would be a common issue, but my search turned up empty. I have two states - one accessed at /route and the other at /route/{name}. Everything functions properly when I navigate to the second route using ui-sref, however, if I r ...

Having trouble with the CKEditor character count function in JavaScript?

I integrated the Javascript and stylesheet from this source into my webpage. http://jsfiddle.net/VagrantRadio/2Jzpr/ However, the character countdown is not appearing on my site. What mistake have I made? ...

Preserve content from a hyperlink using JavaScript

How can I store a value to the cache using JavaScript when clicking on an anchor link? The code below sets up the dynamic content: <a align="left" href="projectoverview.html">Test Manager</a> I want to save the text "Test Manager" to the cach ...

Implementing API calls in NuxtJs (vuex) to be accessible on all routes and pages (using spa mode)

Is it possible to utilize nuxtServerInit in Nuxt's 'spa' mode as well? I am aware it is primarily used when Nuxt is in 'universal' (ssr) mode, but I require the same functionality in 'spa' mode. The purpose of using it i ...

JavaScript/jQuery: Retrieve the correct header for every element

Looking at the given HTML structure (which is just an example and may not be entirely logical): <div id="wrapper"> <h3>First Heading</h3> <div class="row"><div class="col-12"><p class=& ...

Issue: the size of the requested entity is too large

Encountering an error message while using express: Error: request entity too large at module.exports (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:16:15) at json (/Users/ ...

When attempting to install material UI in my terminal, I encounter issues and encounter errors along the way

$ npm install @material-ui/core npm version : 6.14.4 Error: Source text contains an unrecognized token. At line:1 char:15 $ npm install <<<< @material-ui/core CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException ...

What is the purpose of adding "/dist" to the library import statement?

Currently, I am in the process of developing a react component library using vite as my primary build tool. After successfully compiling the project and deploying it to the npm registry, I encountered an issue when importing it into my client app. Specifi ...

Should Redux Reducer deep compare values or should it be done in the Component's ShouldComponentUpdate function?

Within my React Redux application, I have implemented a setInterval() function that continuously calls an action creator this.props.getLatestNews(), which in turn queries a REST API endpoint. Upon receiving the API response (an array of objects), the actio ...

Annoying div unexpectedly wrapping content after using appendTo

Greetings, esteemed members of the SO community, I am here once again with a question that requires your assistance. Context: I am currently working on a grid system that allows users to drag and drop items onto specific grid fields. When the grid is re ...

displaying a div as a pop-up within an ASP.NET MVC 4 web application

One aspect of my asp.net MVC 4 application involves a partial view structured like so: <form class="qty-add" action="#" method="POST"> <label>Qty:</label> <div class="inp-controller"> <a href="#" c ...

Verify the type of email domain (personal or corporate)

Here's an example: isPersonalEmail("<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0aea1ada580a7ada1a9aceea3afad">[email protected]</a>") // true isPersonalEmail("<a href="/cdn-cgi/l/email- ...

What is the best way to convert a table into a data array using jQuery?

I need help with a form and table integration. <form id="form_step" action="form_stepb.php" method="post"> Within the table, there are various rows containing dropdowns and input fields: <table class="data_table ...

Disregard the Field File when utilizing jQuery validation

I have created a form with jQuery validation, but I am facing an issue where the file upload field is showing a message "enter no more than 3 characters." I believe this problem is due to the maxlength="3" property in the file field. How can I remove the ...

Fixing prop passing issues in Vue.js components to prevent errors

My Vue-cli install with TypeScript is set up to render JSX using a boilerplate. However, I am facing an issue when trying to pass a property to the HelloWorld component. Here's what my code looks like: export default Vue.extend({ name: 'App&apo ...

What is the best way to assign multiple values to certain elements within an array?

I have an array that looks like this: items = { item1: 10, item2: 5, item3: 7, item4: 3, }; I am looking to include additional details in this array, for example: items = { item1: 10 {available: true}, ...

What is the best way to ensure the checkbox functions correctly in this specific situation?

I am utilizing PHP, Smarty, and jQuery in the development of my website. Currently, I am working on implementing checkboxes within a Smarty template. Below is a snippet of my Smarty code related to checkboxes: <table cellpadding="5" cellspacing="0" bor ...

How do I verify response values in Postman tests when the input parameter may be empty and can have multiple possible values?

In my program, there is an input parameter known as IsFruit that can have a value of either 0 or 1. If IsFruit is set to 0, the response should return fruits with a FruitsYN value of N. Similarly, if it is set to 1, FruitsYN should be Y. In cases where I ...