浏览代码

修改条数显示

yangg 5 月之前
父节点
当前提交
c2759739fe
共有 1 个文件被更改,包括 10 次插入2 次删除
  1. 10 2
      src/components/SearchResults/index.vue

+ 10 - 2
src/components/SearchResults/index.vue

@@ -86,13 +86,18 @@ export default defineComponent({
     const hasMore = ref(false);
     const searchQuery = ref('');
     const isSearching = ref(false);
+    const localTotal = ref(props.total);
+
+    // 监听props中的total变化
+    watch(() => props.total, (newTotal) => {
+      localTotal.value = newTotal;
+    });
 
     // 监听 searchResults 变化
     watch(() => props.searchResults, (newResults) => {
       displayResults.value = newResults;
       hasMore.value = displayResults.value.length < props.total;
     }, { immediate: true });
-
     // 格式化日期
     const formatDate = (date) => {
       return dayjs(date).format('YYYY-MM-DD');
@@ -122,11 +127,13 @@ export default defineComponent({
           displayResults.value = response.data.data.results || [];
           // 添加调试日志
           console.log('Total Results:', response.data.data.total_results);
+          localTotal.value = response.data.data.total_results || 0;
           emit('update:total', response.data.data.total_results || 0);
         }
       } catch (error) {
         console.error('Web search failed:', error);
         displayResults.value = [];
+        localTotal.value = 0;
         emit('update:total', 0);
       } finally {
         isSearching.value = false;
@@ -137,13 +144,14 @@ export default defineComponent({
     const clearSearch = () => {
       searchQuery.value = '';
       displayResults.value = [];
+      localTotal.value = 0;
       emit('update:total', 0);
     };
 
     return {
       displayResults,
       loading: props.loading,
-      total: props.total,
+      total: localTotal,
       hasMore,
       formatDate,
       searchQuery,