li图标设置

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LI图标设置</title>
<style type="text/css">

</style>
</head>
<body>
<ul>
 <li><img src="img_01.jpg"/></li>
</ul>
<ul>
 <li style="list-style-image: url(img_01.jpg);">论坛</li>
 <li style="list-style-image: url(img_01.jpg);">电影</li>
 <li style="list-style-image: url(img_01.jpg);">登陆</li>
 <li style="list-style-image: url(img_01.jpg);">退出</li>
</ul>
</body>
</html>

注意:img_01.jpg为html文件同目录下的图片

参考内容:http://hi.baidu.com/hooyan/blog/item/9203971126e19c77cb80c489.html

                   http://bbs.blueidea.com/thread-2762049-1-1.html

                   http://www.cssbbs.com/ask/?Ask1234.html

### 创建带图标的列表搜索组件 在 Vue 项目中创建一个带有图标和搜索功能的列表组件可以通过组合多个子组件来完成。以下是具体实现方法: #### 组件结构设计 为了提高可维护性和灵活性,建议将整个功能拆分为三个主要部分:输入框、图标展示以及列表渲染。 - **InputSearch.vue**: 负责处理用户的输入事件并触发父级组件的方法。 - **IconDisplay.vue**: 显示对应的图标,支持三种不同的 API 方式暴露给其他组件使用[^2]。 - **ItemList.vue**: 渲染过滤后的数据项列表,并接收来自 InputSearch 的查询条件作为 prop 属性传递进来。 #### 实现代码示例 ##### IconDisplay.vue (用于显示图标) ```vue <template> <div class="icon-container"> <!-- 使用 slot 可以让调用者自定义内部内容 --> <slot></slot> </div> </template> <script setup lang="ts"> // 这里可以根据实际需求引入不同类型的图标库或本地资源路径 import { defineProps } from 'vue'; const props = defineProps({ iconName: String, }); </script> <style scoped> .icon-container { display: inline-block; } </style> ``` ##### InputSearch.vue (负责收集用户输入) ```vue <template> <input type="text" v-model.trim="searchText" @input="handleInputChange"/> </template> <script setup lang="ts"> import { ref, emit } from 'vue'; const searchText = ref(''); function handleInputChange(event: Event): void { const target = event.target as HTMLInputElement; emit('update:query', target.value); } defineEmits(['update:query']); </script> ``` ##### ItemList.vue (呈现最终的结果集) ```vue <template> <ul> <li v-for="(item, index) in filteredItems" :key="index">{{ item.name }} <IconDisplay :iconName="item.icon"></IconDisplay> </li> </ul> </template> <script setup lang="ts"> import { computed, PropType } from 'vue'; import IconDisplay from './IconDisplay.vue'; interface ListItem { name: string; icon?: string; } const props = defineProps({ items: Array as PropType<ListItem[]>, query: String, }); const filteredItems = computed(() => { if (!props.query || !props.items?.length) return []; return props.items.filter(item => item.name.toLowerCase().includes(props.query!.toLowerCase()) ); }); </script> ``` 最后,在主应用文件 App.vue 或页面级别的 .vue 文件内组装这些模块即可形成完整的交互体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值