Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
hager
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
2024-10-20 18:53:20 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8660e4f35b4cda560070da5ce504b1c8597ecb17
8660e4f3
1 parent
62c01d6c
完善搜索的相关逻辑
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
src/components/common/hagerHeader.vue
src/views/search.vue
src/components/common/hagerHeader.vue
View file @
8660e4f
<!--
* @Date: 2024-09-26 13:42:11
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-10-20 1
3:01:08
* @LastEditTime: 2024-10-20 1
8:49:12
* @FilePath: /hager/src/components/common/hagerHeader.vue
* @Description: 文件描述
-->
...
...
@@ -21,7 +21,7 @@
<el-col :span="24">
<div class="search">
<i class="el-icon-search" style="color: #00477E;"></i>
<input placeholder="搜索" />
<input placeholder="搜索"
v-model="keyword" @blur="goToSearch" @keydown.enter="goToSearch"
/>
</div>
</el-col>
</el-row>
...
...
@@ -289,6 +289,13 @@ export default {
show_menu: false,
margin_top: 0,
// choose_country: false, // 主动选择了国家地区
keyword: '',
}
},
watch: {
// 监听路由参数变化时,更新输入框的值
'$route.query.keyword': function(newKeyword) {
this.keyword = newKeyword || '';
}
},
mounted () {
...
...
@@ -449,6 +456,24 @@ export default {
this.show_menu = false;
$('body').css('overflow', 'auto');
},
goToSearch () {
this.updateURL()
},
updateURL() {
const currentKeyword = this.$route.query.keyword;
// 如果输入的 keyword 和当前路由的 keyword 相同,不做更新
if (this.keyword === currentKeyword) return;
// 使用 Vue Router 动态更新 URL 中的 keyword 参数
this.$router.replace({
path: '/search', // 确保路径不变
query: {
...this.$route.query, // 保留其他可能存在的 query 参数
keyword: this.keyword // 更新 keyword 参数
}
});
}
}
}
</script>
...
...
src/views/search.vue
View file @
8660e4f
<!--
* @Date: 2024-10-20 16:57:48
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-10-20 18:
28:43
* @LastEditTime: 2024-10-20 18:
50:25
* @FilePath: /hager/src/views/search.vue
* @Description: 文件描述
-->
...
...
@@ -66,6 +66,11 @@ export default {
}]
}
},
watch: {
'$route.query.keyword': function(newKeyword) {
this.keyword = newKeyword || '';
}
},
mounted () {
},
methods: {
...
...
Please
register
or
login
to post a comment