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 19:17:59 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
caa549773c90abf6c27925eb5cd4f2a49a74a318
caa54977
1 parent
c11cb3c7
✨ feat(keepAlive模块): 无刷新搭配pinia使用
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
7 deletions
src/common/mixin.js
src/store/index.js
src/views/client/bookDetail.vue
src/views/client/personIndex.vue
src/views/client/videoDetail.vue
src/common/mixin.js
View file @
caa5497
...
...
@@ -50,7 +50,7 @@ export default {
console
.
error
(
err
);
});
},
getProductDetail
(
type
,
id
)
{
getProductDetail
(
type
,
id
)
{
// 查询更新作品详情
axios
.
get
(
'/srv/?a=prod_info'
,
{
params
:
{
prod_id
:
id
...
...
@@ -60,6 +60,8 @@ export default {
if
(
res
.
data
.
code
===
1
)
{
this
.
detail
[
`is_
${
type
}
`
]
=
res
.
data
.
data
[
`is_
${
type
}
`
];
this
.
detail
[
`
${
type
}
_num`
]
=
res
.
data
.
data
[
`
${
type
}
_num`
];
// 传回数据
this
.
$emit
(
'on-click'
,
this
.
detail
);
}
else
{
// tslint:disable-next-line: no-console
console
.
warn
(
res
);
...
...
@@ -76,4 +78,4 @@ export default {
}
}
}
};
\ No newline at end of file
};
...
...
src/store/index.js
View file @
caa5497
...
...
@@ -6,7 +6,8 @@ export const mainStore = defineStore('main', {
msg
:
'Hello world'
,
count
:
0
,
auth
:
false
,
comment_num
:
0
comment_num
:
0
,
video_detail
:
{}
};
},
getters
:
{},
...
...
@@ -16,6 +17,9 @@ export const mainStore = defineStore('main', {
},
changeCommentNum
(
num
)
{
this
.
comment_num
=
num
;
},
changeVideoDetail
(
v
)
{
this
.
video_detail
=
v
;
}
},
});
\ No newline at end of file
});
...
...
src/views/client/bookDetail.vue
View file @
caa5497
...
...
@@ -97,6 +97,9 @@
</template>
<script setup>
import { mainStore } from '@/store'
import { storeToRefs } from 'pinia'
import Cookies from 'js-cookie'
import { useVideoList } from '@/composables/useVideoList.js'
...
...
@@ -113,7 +116,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, onActivated } from 'vue'
import { ref, reactive, onMounted, nextTick, onActivated
, triggerRef
} from 'vue'
import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router'
import axios from '@/utils/axios';
import $ from 'jquery'
...
...
@@ -247,6 +250,21 @@ const uploadVideo = () => {
/****************** keepAlive 模块 *******************/
onActivated(() => { // keepAlive 重置后执行回调
// TAG: pinia应用,动态刷新数据
// 处理数据未刷新数据显示问题
const store = mainStore()
// Pinia 解构方法:storeToRefs
const { video_detail } = storeToRefs(store);
// 如果作品信息有变化及时修正
const arr = ref([]);
_.each(prod_list.value, (item) => {
if (item.id === video_detail.value.id) {
item = video_detail.value
}
arr.value.push(item);
})
// 触发更新
prod_list.value = arr.value;
});
const changeRouterKeepAlive = (path, keepAlive) => {
...
...
src/views/client/personIndex.vue
View file @
caa5497
...
...
@@ -53,6 +53,9 @@
</template>
<script setup>
import { mainStore } from '@/store'
import { storeToRefs } from 'pinia'
import VideoCard from '@/components/VideoCard/index.vue'
import { ref, onActivated } from 'vue'
...
...
@@ -118,6 +121,21 @@ const followUser = (status) => {
/****************** keepAlive 模块 *******************/
onActivated(() => { // keepAlive 重置后执行回调
// TAG: pinia应用,动态刷新数据
// 处理数据未刷新数据显示问题
const store = mainStore()
// Pinia 解构方法:storeToRefs
const { video_detail } = storeToRefs(store);
// 如果作品信息有变化及时修正
const arr = ref([]);
_.each(userInfo.value.prod, (item) => {
if (item.id === video_detail.value.id) {
item = video_detail.value
}
arr.value.push(item);
})
// 触发更新
userInfo.value.prod = arr.value;
});
const changeRouterKeepAlive = (path, keepAlive) => {
...
...
src/views/client/videoDetail.vue
View file @
caa5497
...
...
@@ -13,7 +13,7 @@
</div>
<div class="video-player">
<video-detail :item="videoInfo"></video-detail>
<video-detail :item="videoInfo"
@on-click="onVideoDetail"
></video-detail>
</div>
<div class="video-main">
...
...
@@ -42,7 +42,7 @@ import { storeToRefs } from 'pinia'
import VideoDetail from '@/components/VideoDetail/index.vue'
import { ref, reactive, onMounted, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useRoute, useRouter
, onBeforeRouteLeave
} from 'vue-router'
import axios from '@/utils/axios';
import $ from 'jquery'
import { Toast } from 'vant';
...
...
@@ -112,6 +112,11 @@ onMounted(() => {
console.error(err);
})
})
const onVideoDetail = (v) => {
// 缓存作品信息,给其他页使用
store.changeVideoDetail(v);
}
</script>
<script>
...
...
Please
register
or
login
to post a comment