生活随笔
收集整理的這篇文章主要介紹了
vue 分页查询条件的缓存
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在項目中經常遇到這種情況, 首頁為常見的查詢條件下的表格, 可跳轉詳情頁
從詳情頁返回首頁時, 需緩存用戶上一次的查詢條件若是跳轉其他頁面, 則不緩存查詢條件, 且清空緩存
以下是詳細的代碼實現:
<el-form ref="searchForm" left :model="searchForm" label-position="right" label-width="90px" :inline="true">...
</el-form><el-button type="primary" @click="getList(1)">查 詢
</el-button><el-button @click="resetSearchForm">重 置
</el-button><el-table border :data="tableData" class="el_table">...
<el-table-column label="操作" width="120"><template slot-scope="{row}"><el-button type="text" @click.stop="toDetail(row)">查看
</el-button></template></el-table-column></el-table><el-pagination v-if="isShowPage" ... />
import { sGet
, sSet
, sRemove
} from '@/utils/storage' export default {data () {return {searchForm
: {..., pageNum
: 1,pageSize
: 10},isShowPage
: true }},mounted () {this.getCache() },methods
: {getCache () {this.isShowPage
= falsethis.$nextTick(_ => { this.isShowPage
= true }) this.searchForm
= sGet('searchList_cache') ?? this.searchForm
sRemove('searchList_cache') },toDetail (row) {this.$router
.push(...)sSet('searchList_cache', this.searchForm
) }}
}
! 最后還需要注意, 在系統的菜單切換方法里清除該緩存
menuChange (url) {url
!== this.$route
.path
&& sRemove('searchList_cache')}
總結
以上是生活随笔為你收集整理的vue 分页查询条件的缓存的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。