react-native 电商搜索界面

react-native 电商搜索界面

此界面实现了搜索,自动补全搜索内容,热门搜索,搜索历史记录,清除搜索历史记录等功能,欢迎大家使用
在这里插入图片描述

import React from 'react';
import {
    AppRegistry,
    Text,
    View,
    Button,
    StyleSheet,
    ScrollView,
    Image,
    TextInput,
    Dimensions,
    TouchableOpacity,
      PixelRatio,

} from 'react-native';

import {getsearchinitdata} from "../network/interface";
import AutoSearch from './childComponents/autoSearch'
import axios from 'axios';
import DeviceStorage from '../commen/DeviceStorage';

//获取屏幕的宽度
var {height, width} = Dimensions.get('window');


class Search extends React.Component {
    static navigationOptions = {
        title: 'Search',
    };
    constructor(props){
        super(props);
        this.state={
            historyKeyword: [],            
            defaultKeyword: {},
            hotKeyword: [],
            
             text: '',
            show: false,
            textlist:[],
        }
    };

     //输入框文字改变
    textChange(text){
        console.log(text)
       axios(`https://suggest.taobao.com/sug?code=utf-8&q=${text}`).then(responseJSON=>{
            console.log('11')
            var data=JSON.parse(responseJSON.request._response);

           this.setState({
               show: true,
               text:text,
               textlist: data.result
           });
       })
            .catch(error=>{
                console.log('22')
                console.log(error)})
        console.log('123')


    }

    //隐藏自动提示列表
    hideList(text){
        console.log('hideList')
       // alert("您输入的内容为:"+text);

       this.setState({
            show: false,
            text:text
        });
        setTimeout(()=>{ this.search();},500)//一秒之后自动搜索,不需点击搜索键


    }

    //搜索按钮点击
    search(){
        //搜索之前先存储数据
        //先判断此记录之前是否存在过
        let kw=this.state.historyKeyword;
        let tx=this.state.text;
        console.log(kw.indexOf(tx))
        if(kw.ind
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值