当前位置:   article > 正文

[vue] vue3.x 前端列表搜索过滤_vue3列表过滤组件,按需加载过滤项

vue3列表过滤组件,按需加载过滤项

vue-next-admin,这是基于 vue3.x + CompositionAPI + typescript + vite + element plus + vue-router-next + next.vuex,适配手机、平板、pc 的后台开源免费模板库

一、效果图

在这里插入图片描述

二、组件代码

<template>
	<div class="market-details-container">
		<input type="text" v-model="userSearch" placeholder="请输入姓名" />
		<ul>
			<li v-for="(v, k) in filterUserList" :key="k">姓名:{{ v.name }},年龄:{{ v.age }}</li>
		</ul>
	</div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs, onMounted, computed, getCurrentInstance } from 'vue';
export default defineComponent({
	name: 'marketDetails',
	setup() {
		const { proxy } = getCurrentInstance() as any;
		const state = reactive({
			userSearch: '',
			userList: [],
		});
		onMounted(() => {
			for (let i = 0; i < 10; i++) {
				state.userList.push({
					id: Math.random(),
					name: `
					${unescape(`\\u${(Math.round(Math.random() * 20901) + 19968).toString(16)}`.replace(/\\/g, '%'))}${unescape(
						`\\u${(Math.round(Math.random() * 20901) + 19968).toString(16)}`.replace(/\\/g, '%')
					)}${unescape(`\\u${(Math.round(Math.random() * 20901) + 19968).toString(16)}`.replace(/\\/g, '%'))}
					`,
					age: (Math.random() * 20 + 18).toFixed(0),
				});
			}
		});
		const filterUserList = computed(() => {
			let { userSearch, userList } = proxy;
			let arr = [...userList];
			arr = userList.filter((v) => v.name.indexOf(userSearch) !== -1);
			return arr;
		});
		return {
			filterUserList,
			...toRefs(state),
		};
	},
});
</script>

<style scoped lang="scss">
.market-details-container {
	padding: 50px;
	ul {
		margin-top: 15px;
		li {
			padding: 5px 0;
		}
	}
}
</style>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号