vue:仿百度样式搜索框

效果如图:

html代码如下:

 <div class="box">
              <div class="searchBox">
                <input type="text" v-model="keyword" placeholder="请输入关键词进行搜索" class="searchInput" style="padding-left: 10px;">
                <input type="button"  @click="_search" value="搜索" class="searchButton">
              </div>
            </div>

 

css代码如下:

.box{
    margin: 0 auto;
    padding-top: 80px;
    height: 50px;
    width: 100%;
  }
  .searchBox{
    margin: 0 auto;
    width: 60%;
    position: relative;
  }
  .searchInput{
    display: inline-block;
    width: 85%;
    height: 38px;
    border: 1px solid #cccccc;
    float: left;
    box-sizing: border-box;
    -moz-box-sizing:border-box; /* Firefox */
    -webkit-box-sizing:border-box; /* Safari */
    border-bottom-left-radius: 5px;
    border-top-left-radius: 5px;
  }
  .searchButton{
    display: inline-block;
    width: 15%;
    height: 38px;
    line-height: 40px;
    float: left;
    background-color: #00a0e9;
    font-size: 16px;
    cursor: pointer;
    border-bottom-right-radius: 5px;
    border-top-right-radius: 5px;
    border: none;
    color: #fff;
  }

 

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue和Element UI可以很容易地实现类似百度搜索框的功能。首先,我们需要安装Vue和Element UI,可以通过npm或者直接引入CDN来获取相关的依赖。然后在Vue实例中引入Element UI的组件。 在我们的模板中,我们可以使用element-ui的<el-input>组件来创建搜索框。我们可以设置该组件的placeholder属性为“请输入搜索内容”,并且使用v-model指令将输入的值绑定到data中的一个变量上,比如searchInput。 然后,我们可以使用element-ui的<el-button>组件来创建一个搜索按钮,当用户点击按钮时,可以触发一个search方法。 在methods中,我们可以定义一个search方法,该方法将会使用searchInput的值来进行搜索。在这个例子中,我们可以简单地打印searchInput的值来模拟搜索操作。 最后,我们在template中将这些组件和方法结合起来,以实现类似百度搜索框的功能。 ```vue <template> <div> <el-input placeholder="请输入搜索内容" v-model="searchInput" ></el-input> <el-button type="primary" @click="search">搜索</el-button> </div> </template> <script> export default { data() { return { searchInput: '' } }, methods: { search() { console.log(this.searchInput); // 这里可以进行搜索操作,比如发送请求给后端进行搜索 } } } </script> ``` 通过以上的代码,我们就可以在vue和Element UI中实现类似百度搜索框的功能。当用户输入搜索内容后,点击搜索按钮,就可以触发搜索操作。你可以将search方法更新为实际的搜索逻辑,并且利用searchInput的值发送请求给后端进行搜索。这样就可以实现一个真正的搜索功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值