laravel - 刷新页面时保持在数据表中输入的搜索值vue.js
问题描述
刷新后如何保持页面中过滤的值。当我路由回此视图时,使用最后选择的值填充过滤的项目。
<vk-datatable
:columns="columns"
:rows="filteredProducts"
:per_page="8"
:actions="actions"
v-on:row_click="rowClick"
v-on:row_delete="rowDelete"
v-on:row_edit="rowClick"
v-if="filteredProducts"
:loadingPropData="$apollo.queries.products.loading"
></vk-datatable>
解决方案
如果您定期重新加载页面,那么您只需要在输入上使用模型并将输入的值保存到本地存储(例如)。在页面加载时,将本地存储中的值插入到 create 挂钩中的每个模型中。 https://vuejs.org/v2/guide/forms.html(对于选择输入相同)
<template>
<div>
...
<input v-model="userName"
@input.trim="handleInput('userName', $event)"/>
...
</div>
</template>
<script>
export default {
name: 'ComponentName',
data: () => ({
userName: null
}),
methods: {
handleInput(key, {target}) {
const storageData = {[key]: target.value};
localStorage.setItem('storageKey', JSON.stringify(storageData));
},
/* with debounce */
handleInput2: _.debounce(function (key, {target}) {
const storageData = {[key]: target.value};
localStorage.setItem('storageKey', JSON.stringify(storageData));
}, 500),
},
created() {
this.userName = (JSON.parse(localStorage.getItem('storageKey')) || {}).userName; // value or null
}
}
</script>
推荐阅读
- c# - LINQ 按同一列连接多个表
- reactjs - CRUD API React - 方法不允许 405
- scala - 如何从 Mill build.sc 文件中的 Seq[Path] 创建源?
- python - Python – 函数头中的“类型”错误
- flutter - Flutter - 预期:应该按顺序执行以下操作:发出事件 Empty、NumberTriviaError、Actual:Empty:这不是 Stream 或 SteamQue
- python - 使用 Python 将一列拆分为多行
- node.js - Strapi 如何在控制器中增加 api
- html - 悬停时填充整个有角度的 li 标签
- javascript - 如何更新 React Redux 中的状态?
- c++ - QML 中未调用函数