赞
踩
<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>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。