index.jsx 950 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Component } from "react";
  2. import Taro from "@tarojs/taro";
  3. import { View } from "@tarojs/components";
  4. import SearchBar from "../../components/index/SearchBar"; //搜索框
  5. import "./index.less";
  6. export default class Index extends Component {
  7. state = {};
  8. handleSearch = (value) => {
  9. if (value.trim() === '') {
  10. Taro.showToast({
  11. title: '请输入搜索内容',
  12. icon: 'none'
  13. })
  14. return;
  15. }else{
  16. Taro.navigateTo({
  17. url: `/pages/indexSub/searchList/index?keyword=${value}`
  18. })
  19. }
  20. }
  21. handleChange = (value) => {
  22. this.setState({ value }); // 更新状态
  23. }
  24. render() {
  25. return (
  26. <View className="index">
  27. {/* 搜索框 */}
  28. <SearchBar
  29. value={this.state.value}
  30. onChange={this.handleChange}
  31. onSearch={this.handleSearch}
  32. placeholder="搜索商品"
  33. disabled={false}
  34. />
  35. </View>
  36. );
  37. }
  38. }