小程序P114 07.搜素-自定义组件-渲染my-search组件的基本结构
!!!新版的Hbuilder的components叫做uni_modules
!!!在uni-ui的基础上新建components就行
uni-app官网:https://uniapp.dcloud.net.cn/component/uniui/uni-icons.html
1、在分类页面的 UI 结构中,直接以标签的形式使用 my-search 自定义组件:
<!-- 使用自定义的搜索组件 -->
<my-search></my-search>
2、定义 my-search 组件的 UI 结构如下:
<template>
<view class="my-search-container">
<!-- 使用 view 组件模拟 input 输入框的样式 -->
<view class="my-search-box">
<uni-icons type="search" size="17"></uni-icons>
<text class="placeholder">搜索</text>
</view>
</view>
</template>
!!!<uni-icons type="search" size="17"></uni-icons>会渲染出错
可以改为:<icon type="search" size="17"></icon>
!!!或者把uni_modules的文件复制到components
3、由于自定义的 my-search 组件高度为 50px,因此,需要重新计算分类页面窗口的可用高度:
//在cate.vue里面
onLoad() {
const sysInfo = uni.getSystemInfoSync()
// 可用高度 = 屏幕高度 - navigationBar高度 - tabBar高度 - 自定义的search组件高度
this.wh = sysInfo.windowHeight - 50
}
- 复制链接
- 举报