fix: not login
This commit is contained in:
@@ -24,9 +24,10 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import ActionBadge from "@/components/ActionBadge/ActionBadge.vue";
|
||||
import { topicItemCommentLike } from "@/api/topicItem";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
|
||||
const props = defineProps({
|
||||
comment: {
|
||||
@@ -36,6 +37,10 @@ const props = defineProps({
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['need-login']);
|
||||
const userStore = useUserStore();
|
||||
const isLoggedIn = computed(() => !!userStore.token || !!userStore.userInfo?.nickName);
|
||||
|
||||
const isLiked = ref(props.comment.isLiked || false);
|
||||
const currentLikes = ref(props.comment.likes || 0);
|
||||
let isLiking = false; // 防抖标志
|
||||
@@ -49,6 +54,11 @@ watch(() => props.comment.isLiked, (newVal) => {
|
||||
});
|
||||
|
||||
const handleLike = async () => {
|
||||
if (!isLoggedIn.value) {
|
||||
emit('need-login');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLiking) return;
|
||||
isLiking = true;
|
||||
|
||||
@@ -206,4 +216,4 @@ const handleLike = async () => {
|
||||
line-height: 1.65;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user