通过关键字搜索

该代码示例展示了如何在Vue.js应用中创建一个具有搜索功能和下拉选择列表的组件。使用`u-search`组件,实现了搜索框的样式定制,包括背景色、边框颜色、占位符等属性,并通过数据绑定和事件监听处理选择项的点击和显示隐藏操作。
摘要由CSDN通过智能技术生成

<template>
    <view class="content">
        <u-search :showAction="true" actionText="搜索" :animation="true"
        placeholder="请输入关键字" bgColor="#f0f0f0" borderColor="#ff0000"
        searchIconColor="#3f3f3f" searchIconSize=18 margin="10px"
        :actionStyle="actionStyle" :label="choiceList[choiceIndex].one_name"
        searchIcon="arrow-down-fill" @clickIcon="btnShowHideClick"
        ></u-search>
        <view class="dialog-view" v-if="isShowChoice">
            <text :class="choiceIndex == index ?'dialog-title-selected':'dialog-title'"
                v-for="(item ,index) in choiceList" @click="btnChoiceClick(index)">{{item.one_name}}</text>
        </view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                choiceContent: '请选择',
                isShowChoice: false,
                choiceIndex: 0,
                choiceList: [
                    {
                        "one_id": 15,
                        "one_name": "牛奶",
                        "two_id": 0,
                        "two_name": "无"
                    },
                    {
                        "one_id": 11,
                        "one_name": "羊奶",
                        "two_id": 18,
                        "two_name": "酸奶"
                    },
                    {
                        "one_id": 11,
                        "one_name": "羊奶",
                        "two_id": 17,
                        "two_name": "芒果"
                    }
                ],
                actionStyle:{
                    background: 'linear-gradient(180deg, #01A2F0 0%, #76D8E4 100%)',
                    borderRadius: '8px',
                    fontSize: '14px',
                    color: '#FFFFFF',
                    lineHeight: '30px',
                    border: 'none',
                    margin:'6px'
                },
                keyword:""
            }
        },
        methods: {
            // 选择
            btnChoiceClick(index){
                console.log(index)
                this.choiceIndex = index
                this.choiceContent = this.choiceList[index]
            },
            // 显示与隐藏选择内容
            btnShowHideClick() {
                this.isShowChoice = !this.isShowChoice
            }
        }
    }
</script>
<style>
    .dialog-view {
        display: flex;
        flex-direction: column;
        justify-content: center;
        text-align: center;
        font-size: 14px;
        margin-left: 10px;
        width: 100px;
        border: 1rpx solid #e7e7e7;
        box-sizing: border-box;
        border-radius: 15px;
        padding: 10px 0px;
        background-color: white;
    }
    .dialog-title {
        color: black;
        background-color: white;
        padding: 5px 0px;
    }
    .dialog-title-selected {
        color: white;
        background-color: #ff87a3;
        padding: 5px 0px;
    }
</style>
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值