简体   繁体   English

单击链接后如何在输入中保存价值?

[英]How can I save value in input after click on link?

I have a search that works with ajax. 我有一个适用于ajax的搜索。 If the user clicks on one of the seach results, he gets on a new page. 如果用户单击搜索结果之一,则他会进入新页面。 Now, if he klicks back on the browser UI, he gets back to the search. 现在,如果他在浏览器UI上弹回,他将返回搜索。 However, the value from the input is not getting saved and the search is empty. 但是,输入的值未保存,搜索为空。 I would like to have keep the value. 我想保留价值。

The search is programmed in vue.js: 搜索在vue.js中编程:

<template>
    <div>
        <div class="row">
            <div class="col-12">
                <div class="card no-shadow-card mb-2">
                    <div class="card-header primary-color white-text">
                        <div class="d-flex justify-content-between">
                            <span>Filter</span>
                            <div>
                                <a href="javascript:void(0)" class="card-toggle-body-visibility white-text"><i
                                        class="fa fa-chevron-up rotated-icon" aria-hidden="true"></i></a>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="form-row mb-4">
                            <div class="col-md-6 mb-1">
                                <!-- First name -->
                                <input type="text" id="vacancieName" data-reset="filter"
                                       class="form-control" placeholder="Name der Stellenanzeige" v-model="name">
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="col-md-6">
                                <select class="md-form mdb-select"
                                        name=""
                                        searchable="Suchen"
                                        v-model="company">
                                    <option value="">Unternehmen</option>
                                    <option v-for="ownCompany in ownCompanies" :value="ownCompany.id" v-text="ownCompany.title"></option>
                                </select>
                                <button type="button" class="btn-save btn btn-primary btn-sm">Ok</button>
                            </div>
                            <div class="col-md-6">
                                <select class="md-form mdb-select"
                                        name=""
                                        searchable="Suchen"
                                        v-model="job">
                                    <option value="" disabled>Beruf Auswählen</option>
                                    <option v-for="avalibleJob in avalibleJobs" :value="avalibleJob.id" v-text="avalibleJob.name"></option>
                                </select>
                                <button type="button" class="btn-save btn btn-primary btn-sm">Ok</button>
                            </div>
                        </div>
                        <div class="col-12 float-right">
                            <button @click.prevent="getVacancies" type="button" class="btn btn-sm btn-light-blue">
                                Suchen
                            </button>
                            <button @click="resetFilter" type="button" class="btn btn-sm btn-unique">
                                Zurücksetzen
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <vacancie-index-result-componment v-for="vacancie in vacancies" v-bind:vacancie="vacancie"
                                              :key="vacancie.id"></vacancie-index-result-componment>
        </div>
    </div>
</template>

<script>
    import VacancieIndexResultComponentComapany from './VacancieIndexResultComponentCompany.vue'

    export default {
        name: 'VacancieIndexComponentCompany',
        components: {
            'vacancie-index-result-componment': VacancieIndexResultComponentComapany,
        },
        data() {
            return {
                avalibleJobs: [],
                ownCompanies: [],
                vacancies: [],
                name: '',
                company: '',
                job: ''
            }
        },
        methods: {}//Some Axios methods to get the results
    }
</script>

There are two ways to resolve your problems 有两种方法可以解决您的问题

  1. Use dialog to handle your new page,above the <body></body> or your root element ,it coast less code to resolve. 使用对话框来处理您的新页面,在<body></body>或您的根元素上方,它减少了要解析的代码。 it's will hold the code in a single component 它会将代码保存在单个组件中
  2. Hard way or the best way whatever you say, is to use the vue-route system, use <keep-alive></keep-alive> tags to cache your components, and you'll see the value is still there.you can also see it in dev-tools anyway. 无论怎么说,最好的方法就是使用vue-route系统,使用<keep-alive></keep-alive>标签来缓存您的组件,您会发现该值仍然存在。也可以在开发工具中看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (XPages)单击按钮后如何将值保存在文档中? - (XPages)How can I save the value in document after click button? 单击按钮后如何清除输入值? - how can i clean the input value after i click the button? 单击跨度时,如何获取由跨度标签括起来的文本并将其保存为隐藏的输入值? - How can get the text enclosed by a span tag and save it to a hidden input value when I click the span? 单击链接后如何保存href值 - How can i save the href value after a link has been clicked 如何保存输入值并将其放入其他输入中? - How can I save input value and put the value in other input? click事件修改后,如何获取HTML输入的新值? - How can I get the new value of an HTML input after a click event has modified it? 如何在链接点击时获取输入字段值? - How to get input field value on link click? XCode:如何将JavaScript输入到UIWebView中以单击链接(但是每次链接都不同) - XCode: How can I input javascript into UIWebView to click on a link (but the link is different each time) 如何将多个输入框的值保存到本地存储? - How can I save the value of multiple input boxes to local storage? 如何从按钮单击事件中获取输入值? - How can I get the value of an input from a button click event?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM