Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
tswj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2022-05-12 12:28:16 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1e53fe179f659691f09d314b23cb00176fcec21f
1e53fe17
1 parent
8af2dbf6
✨ feat(下拉加载页面): keepAlive缓存相应页面
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
13 deletions
src/App.vue
src/route.js
src/views/business/login.vue
src/views/client/bookDetail.vue
src/views/me/callMe.vue
src/views/me/index.vue
src/views/me/message.vue
src/App.vue
View file @
1e53fe1
<template>
<router-view></router-view>
<!-- 页面缓存 -->
<router-view v-slot="{ Component }">
<keep-alive>
<component :is="Component" :key="$route.name" v-if="$route.meta.keepAlive"/>
</keep-alive>
<component :is="Component" :key="$route.name" v-if="!$route.meta.keepAlive"/>
</router-view>
</template>
<script setup>
...
...
@@ -37,6 +43,32 @@ if (!Cookies.get('default_perf')) {
}
</script>
<script>
import _ from 'lodash';
export default {
beforeRouteEnter(to, from, next) {
// 如果是从下面页面返回,需要重置keepAlive状态
const arr = ['/me/message', '/me/callMe', '/client/bookDetail'];
if (_.findIndex(arr, (path) => path === from.path) !== -1) {
from.meta.keepAlive = false;
}
next();
},
data() {
return {
}
},
mounted() {
},
methods: {
}
}
</script>
<style lang="less">
html,
body {
...
...
src/route.js
View file @
1e53fe1
...
...
@@ -35,7 +35,8 @@ export default [{
name
:
'客户端选择书籍下视频作品'
,
component
:
()
=>
import
(
'./views/client/bookDetail.vue'
),
meta
:
{
title
:
'书籍'
title
:
'书籍'
,
keepAlive
:
true
},
children
:
[]
},
{
...
...
@@ -169,7 +170,8 @@ export default [{
name
:
'我的留言'
,
component
:
()
=>
import
(
'./views/me/message.vue'
),
meta
:
{
title
:
'我的留言'
title
:
'我的留言'
,
keepAlive
:
true
},
children
:
[]
},
{
...
...
@@ -177,7 +179,8 @@ export default [{
name
:
'@我的'
,
component
:
()
=>
import
(
'./views/me/callMe.vue'
),
meta
:
{
title
:
'@我的'
title
:
'@我的'
,
keepAlive
:
true
},
children
:
[]
},
{
...
...
src/views/business/login.vue
View file @
1e53fe1
...
...
@@ -129,9 +129,9 @@ const sendCode = () => { // 发送验证码
})
}
};
const phone = ref('');
const code = ref('');
// TEMP:测试数据
const phone = ref('
13812345678
');
const code = ref('
8888
');
const disabled = ref(true);
// 过滤输入的数字 只能四位
const formatter = (value) => value.substring(0, 4);
...
...
src/views/client/bookDetail.vue
View file @
1e53fe1
...
...
@@ -113,7 +113,7 @@ import icon_unsubscribe from '@images/icon-dingyue02@2x.png'
import ShortcutFixed from '@/components/ShortcutFixed/index.vue'
import tools from '@/common/tool'
import { ref, reactive, onMounted, nextTick } from 'vue'
import { ref, reactive, onMounted, nextTick
, onActivated
} from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from '@/utils/axios';
import $ from 'jquery'
...
...
@@ -243,6 +243,10 @@ const uploadVideo = () => {
console.error(err);
})
}
onActivated(() => { // keepAlive重置后执行回调
onLoad()
});
</script>
<script>
...
...
src/views/me/callMe.vue
View file @
1e53fe1
...
...
@@ -54,7 +54,7 @@
import CommentBox from '@/components/CommentBox/index.vue'
import NoticeOverlay from '@/components/NoticeOverlay/index.vue'
import { ref, reactive, on
Moun
ted } from 'vue'
import { ref, reactive, on
Activa
ted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from '@/utils/axios';
import _ from 'lodash'
...
...
@@ -201,9 +201,9 @@ const onClick = (item) => {
});
}
onMounted(() => {
})
onActivated(() => { // keepAlive重置后执行回调
onLoad()
});
</script>
<script>
...
...
src/views/me/index.vue
View file @
1e53fe1
...
...
@@ -286,6 +286,12 @@ const getUnwatch = () => {
import mixin from 'common/mixin';
export default {
beforeRouteEnter(to, from, next) {
if (from.path === '/me/message' || from.path === '/me/callMe') { // 如果是从[我的留言,@me]页面返回,需要重置keepAlive状态
from.meta.keepAlive = false;
}
next();
},
mixins: [mixin.init],
data() {
return {
...
...
src/views/me/message.vue
View file @
1e53fe1
...
...
@@ -45,7 +45,7 @@
<script setup>
import icon_player from '@images/bofang@2x.png'
import { ref, reactive, onMounted } from 'vue'
import { ref, reactive, onMounted
, onActivated
} from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from '@/utils/axios';
import _ from 'lodash'
...
...
@@ -75,6 +75,7 @@ const onLoad = () => {
item.c_name = arr[1]; // 评论姓名
})
commentList.value = _.concat(commentList.value, res.data.data);
commentList.value = _.uniqBy(commentList.value, 'id');
offset.value = commentList.value.length;
loading.value = false;
// 数据全部加载完成
...
...
@@ -135,6 +136,10 @@ const deleteComment = (item) => { // 删除评论
// on cancel
});
}
onActivated(() => { // keepAlive重置后执行回调
onLoad()
});
</script>
<script>
...
...
Please
register
or
login
to post a comment