[英]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 有两种方法可以解决您的问题
<body></body>
or your root element ,it coast less code to resolve. 使用对话框来处理您的新页面,在<body></body>
或您的根元素上方,它减少了要解析的代码。 it's will hold the code in a single component 它会将代码保存在单个组件中 <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.