How to set session value input in Vue.js-PHP Chinese Network Q&A
How to set session value input in Vue.js
P粉147045274
P粉147045274 2023-08-25 21:15:59
0
1
433

I have a Vue.js form filter:

           

I have a methods to get the input and selected values:

methods: { changeFilter() { console.log(this.name, this.gender) }, },

Now I want to reload the page but the input box or select box still shows the value I selected. please help me. Thank you

P粉147045274
P粉147045274

reply all (1)
P粉885035114

Okay, so the first good practice is not to use cangeFilter() on the click event, but to use changeFilter. So if I understand you correctly, you want to reload the page and still have the same value selected. You can save this value in local storage, assuming it's not sensitive data.

Local storage informationSave data in local storage

localStorage.setItem('gender', 'Male');

Get data (you need to use a life cycle hook like mounted to initialize the data)

mounted() { this.gender = localStorage.getItem('gender') || '你的默认值'; } 

Values in HTML input form

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!