最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript實(shí)現(xiàn)一個(gè)輸入框組件

 更新時(shí)間:2021年09月12日 10:11:53   作者:Aaron_1127  
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)一個(gè)輸入框組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了手動(dòng)實(shí)現(xiàn)一個(gè)輸入框組件的具體代碼,供大家參考,具體內(nèi)容如下

背景

taro h5中想要實(shí)現(xiàn)一個(gè)樣式如下的輸入框:

問題:

taro組件和taro-ui組件中都沒有這種樣式的組件,taro h5 中還不支持修改placeholder的樣式,自己嘗試著實(shí)現(xiàn)一個(gè)input組件,更能靈活的定義其中的樣式。

實(shí)現(xiàn)

js代碼

import Taro, { Component } from '@tarojs/taro';
import { View } from '@tarojs/components';
import { AtIcon } from 'taro-ui';

import './index.scss';

/**
 * @description 手動(dòng)實(shí)現(xiàn)一個(gè)輸入框組件
 * @param placeholder:String 自定義輸入框中的占位符
 * @param onClickSearch:Function 獲取輸入內(nèi)容回調(diào)
 */
class BaseInput extends Component {
  componentDidMount() {
    //輸入框聚焦
    document.querySelector('.search').focus();
  }

  handleSearch = () => {
    //獲取輸入框的內(nèi)容
    const value = document.querySelector('.search').innerText;
    this.props.onClickSearch && this.props.onClickSearch(value);
  };

  render() {
    const { placeholder = '請(qǐng)輸入' } = this.props;
    return (
      <View className="base_input">
        <View className="my_search">
          <AtIcon
            value="search"
            color="#999"
            className="search_icon"
            onClick={this.handleSearch}
          />
          {/* contenteditable可以控制一個(gè)div是否可以編輯 */}
          <View
            className="search"
            contenteditable
            placeholder={placeholder}
          ></View>
        </View>
      </View>
    );
  }
}
export default BaseInput;

scss代碼

.base_input {
  .my_search {
    box-sizing: border-box;
    width: 690px;
    height: 56px;
    line-height: 56px;
    border-radius: 28px;
    margin: 12px auto;
    background: #f8f8f8;
    display: flex;
    .search_icon {
      width: 30px;
      height: 30px;
      margin-left: 20px;
      margin-right: 18px;
    }
    .search {
      width: 560px;
      padding: 0px 18px;
      background: #f8f8f8;
      height: 56px;
      color: #999;
      font-size: 28px;
      font-weight: 400;
      &:empty::after {
        content: attr(placeholder);
      }
    }
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

黄梅县| 江北区| 北票市| 高要市| 兴国县| 莱州市| 和龙市| 璧山县| 平山县| 永修县| 丰顺县| 樟树市| 武安市| 太白县| 泰安市| 南乐县| 和顺县| 武安市| 天峨县| 万山特区| 石家庄市| 右玉县| 舟曲县| 扶绥县| 大城县| 嵊州市| 朔州市| 汝南县| 环江| 东安县| 柳河县| 洪湖市| 渭源县| 长丰县| 灵宝市| 台前县| 无为县| 南安市| 获嘉县| 大埔县| 上高县|