fix(SearchPopup): 修复导航栏标题在弹窗关闭时未重置的问题
将onMounted改为watch监听visible变化,在弹窗关闭时重置导航栏标题
Showing
1 changed file
with
15 additions
and
7 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-01-20 00:00:00 | 2 | * @Date: 2025-01-20 00:00:00 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-07-04 16:05:59 | 4 | + * @LastEditTime: 2025-07-04 16:10:26 |
| 5 | * @FilePath: /jgdl/src/components/SearchPopup.vue | 5 | * @FilePath: /jgdl/src/components/SearchPopup.vue |
| 6 | * @Description: 搜索弹窗组件 | 6 | * @Description: 搜索弹窗组件 |
| 7 | --> | 7 | --> |
| ... | @@ -128,7 +128,7 @@ | ... | @@ -128,7 +128,7 @@ |
| 128 | </template> | 128 | </template> |
| 129 | 129 | ||
| 130 | <script setup> | 130 | <script setup> |
| 131 | -import { ref, computed, onMounted } from 'vue' | 131 | +import { ref, computed, watch } from 'vue' |
| 132 | import Taro from '@tarojs/taro' | 132 | import Taro from '@tarojs/taro' |
| 133 | import { Search2, Check, Heart1, HeartFill } from '@nutui/icons-vue-taro' | 133 | import { Search2, Check, Heart1, HeartFill } from '@nutui/icons-vue-taro' |
| 134 | import "./SearchPopup.less" | 134 | import "./SearchPopup.less" |
| ... | @@ -408,11 +408,19 @@ const resetSearchState = () => { | ... | @@ -408,11 +408,19 @@ const resetSearchState = () => { |
| 408 | selectedSchool.value = '所在学校' | 408 | selectedSchool.value = '所在学校' |
| 409 | } | 409 | } |
| 410 | 410 | ||
| 411 | -onMounted(() => { | 411 | +// 监听visible.value的变化 |
| 412 | - // 动态修改标题 | 412 | +watch(visible, (newVisible) => { |
| 413 | - wx.setNavigationBarTitle({ | 413 | + if (newVisible) { |
| 414 | - title: '搜索车源' | 414 | + // 动态修改标题 |
| 415 | - }); | 415 | + wx.setNavigationBarTitle({ |
| 416 | + title: '搜索车源' | ||
| 417 | + }); | ||
| 418 | + } else { | ||
| 419 | + // 关闭弹窗时重置标题 | ||
| 420 | + wx.setNavigationBarTitle({ | ||
| 421 | + title: '' | ||
| 422 | + }); | ||
| 423 | + } | ||
| 416 | }) | 424 | }) |
| 417 | </script> | 425 | </script> |
| 418 | 426 | ... | ... |
-
Please register or login to post a comment