实现简易的搜索功能

This commit is contained in:
sunyuqiang
2023-08-10 22:09:04 +08:00
parent 06d2d9bfbc
commit 5857af30b9
5 changed files with 62 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
<template>
<div class="result">
<PluginList
v-if="result && !!result.length"
@downloadSuccess="downloadSuccess"
:title="$t('feature.market.searchResult')"
:list="result"
/>
</div>
</template>
<script setup>
import { computed } from 'vue';
import PluginList from './plugin-list.vue';
import { useStore } from 'vuex';
const store = useStore();
const totalPlugins = computed(() => store.state.totalPlugins);
const searchValue = computed(() => store.state.searchValue);
const result = computed(() => {
if (searchValue.value.trim().length > 0) {
const pattern = new RegExp(searchValue.value);
return totalPlugins.value.filter((plugin) => {
if (plugin.pluginName.match(pattern)) {
return true;
} else {
return false;
}
});
} else {
return totalPlugins.value;
}
});
</script>
<style lang="less">
.result {
width: 100%;
height: 100vh;
overflow-x: hidden;
box-sizing: border-box;
}
</style>