Commit ad03228a authored by huangjie's avatar huangjie

F5刷新不关闭页面

parent a4b6e2e6
<template> <template>
<div id="tags-view-container" class="tags-view-container"> <div id="tags-view-container" class="tags-view-container">
<div id="getviews">
<div class="alltags" v-if="visitedViews.length > 0"> <div class="alltags" v-if="visitedViews.length > 0">
<div class="imgs" @click="closeall"> <div class="imgs" @click="closeall">
<img src="@/assets/images/all.png" v-if="!showall"/> <img src="@/assets/images/all.png" v-if="!showall"/>
...@@ -59,6 +60,7 @@ ...@@ -59,6 +60,7 @@
<li @click="closeAllTags(selectedTag)"><i class="el-icon-circle-close"></i> 全部关闭</li> <li @click="closeAllTags(selectedTag)"><i class="el-icon-circle-close"></i> 全部关闭</li>
</ul> </ul>
</div> </div>
</div>
</template> </template>
<script> <script>
...@@ -118,6 +120,7 @@ export default { ...@@ -118,6 +120,7 @@ export default {
$route() { $route() {
this.addTags() this.addTags()
this.moveToCurrentTag() this.moveToCurrentTag()
this.getviews()
}, },
visible(value) { visible(value) {
if (value) { if (value) {
...@@ -130,8 +133,27 @@ export default { ...@@ -130,8 +133,27 @@ export default {
mounted() { mounted() {
this.initTags() this.initTags()
this.addTags() this.addTags()
// this.getviews()
}, },
methods: { methods: {
getviews(){
let viewlist = []
let views = this.$store.state.tagsView.visitedViews
views.forEach(view =>{
let li = {}
li.fullPath = view.fullPath
li.hash = view.hash
li.meta = view.meta
li.name = view.name
li.params = view.params
li.path = view.path
li.query = view.query
li.title = view.title
// li.matched = view.matched //此条数据放出会报错
viewlist.push(li)
})
localStorage.setItem("views",JSON.stringify(viewlist))
},
changetags(){ changetags(){
this.showall = false this.showall = false
}, },
......
...@@ -21,6 +21,7 @@ import ResizeMixin from './mixin/ResizeHandler' ...@@ -21,6 +21,7 @@ import ResizeMixin from './mixin/ResizeHandler'
import { mapState } from 'vuex' import { mapState } from 'vuex'
import variables from '@/assets/styles/variables.scss' import variables from '@/assets/styles/variables.scss'
import elementResizeDetectorMaker from "element-resize-detector" import elementResizeDetectorMaker from "element-resize-detector"
import { parse,stringify } from 'flatted';
export default { export default {
name: 'Layout', name: 'Layout',
components: { components: {
...@@ -64,10 +65,11 @@ export default { ...@@ -64,10 +65,11 @@ export default {
this.listenSider() this.listenSider()
}) })
// console.log(9999) // console.log(9999)
// let views = localStorage.getItem('views') let views = localStorage.getItem('views')
// console.log(views) if(views!=null){
// this.$store.state.tagsView.visitedViews = JSON.parse(views) this.$store.state.tagsView.visitedViews = JSON.parse(views)
// localStorage.removeItem('views') localStorage.removeItem('views')
}
}, },
methods: { methods: {
handleClickOutside() { handleClickOutside() {
......
import {parse, stringify} from 'flatted';
import { parse,stringify } from 'flatted';
const state = { const state = {
visitedViews: [], visitedViews: [],
cachedViews: [], cachedViews: [],
...@@ -22,8 +23,27 @@ const mutations = { ...@@ -22,8 +23,27 @@ const mutations = {
}) })
) )
// console.log(state.visitedViews) // console.log(state.visitedViews)
// let visitedViews = stringify(state.visitedViews) // try {
// localStorage.setItem("views",visitedViews) // stringify(view)
// }catch(e)
// {
//
// }
// console.log(
// localStorage.removeItem('views')
// let views =view
// let viewlist = localStorage.getItem("views")==null?[]:JSON.parse(localStorage.getItem("views"))
// let li = {}
// li.fullPath = view.fullPath
// li.hash = view.hash
// li.meta = view.meta
// li.name = view.name
// li.params = view.params
// li.path = view.path
// li.query = view.query
// viewlist.push(li)
// viewlist.push(parse(stringify(view)))
// localStorage.setItem("views",stringify(viewlist))
}, },
ADD_CACHED_VIEW: (state, view) => { ADD_CACHED_VIEW: (state, view) => {
if (state.cachedViews.includes(view.name)) return if (state.cachedViews.includes(view.name)) return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment