File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed
Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 11<template >
2- <v-lazy >
2+ <v-lazy v-model = " isActive " >
33 <v-card class =" mb-3" flat outlined ref =" commentCard" >
44 <CommentCardBar :comment =" comment" >
55 <template v-slot :headerAvatar =" { localComment } " >
@@ -182,6 +182,10 @@ import ReplySection from '@/components/courses/ReplySection';
182182export default {
183183 props: {
184184 comment: Object ,
185+ disableLazy: {
186+ type: Boolean ,
187+ default: false ,
188+ },
185189 },
186190 components: {
187191 CommentCardContent,
@@ -211,6 +215,21 @@ export default {
211215 showSnackbar,
212216 };
213217 },
218+ data () {
219+ return {
220+ localIsActive: false ,
221+ };
222+ },
223+ computed: {
224+ isActive: {
225+ get () {
226+ return this .disableLazy || this .localIsActive ;
227+ },
228+ set (val ) {
229+ this .localIsActive = val;
230+ },
231+ },
232+ },
214233 mounted () {
215234 this .formStatus .likeStatus = this .comment .like_status ;
216235 },
Original file line number Diff line number Diff line change 3939 v-for =" (comment, index) in selectedComment"
4040 :key =" comment.id"
4141 cols =" 12"
42+ :data-comment-id =" comment.id"
43+ :ref =" `comment-${comment.id}`"
4244 >
4345 <CourseCommentCard
4446 :comment =" comment"
47+ :disableLazy =" comment.id === shareAnswer"
4548 v-if =" !status.commentLoading && !status.detailLoading"
4649 >
4750 </CourseCommentCard >
@@ -154,6 +157,25 @@ export default {
154157 this .selectedComment .splice (itemIndex, 1 );
155158 this .selectedComment .unshift (shareComment);
156159 },
160+ scrollToAnswer () {
161+ if (this .shareAnswer === - 1 || this .status .commentLoading ) return ;
162+
163+ this .$nextTick (() => {
164+ // 多次尝试滚动,以处理v-lazy的懒加载延迟
165+ const scrollAttempts = () => {
166+ const element = document .querySelector (
167+ ` [data-comment-id="${ this .shareAnswer } "]`
168+ );
169+ if (element) {
170+ element .scrollIntoView ({ behavior: ' smooth' , block: ' start' });
171+ } else {
172+ // 如果元素不存在,可能还在等待v-lazy渲染,再试一次
173+ setTimeout (scrollAttempts, 300 );
174+ }
175+ };
176+ scrollAttempts ();
177+ });
178+ },
157179 },
158180 watch: {
159181 selectedTeachers: {
@@ -166,6 +188,7 @@ export default {
166188 commentText: {
167189 handler () {
168190 this .updateSelectedComment ();
191+ this .scrollToAnswer ();
169192 },
170193 immediate: true ,
171194 deep: true ,
You can’t perform that action at this time.
0 commit comments