Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用map创建子组件时,子组件无法更新,需要console或者添加空style。 #4115

Closed
CodeRabbitYu opened this issue Aug 8, 2019 · 6 comments
Assignees

Comments

@CodeRabbitYu
Copy link

CodeRabbitYu commented Aug 8, 2019

问题描述
[问题描述:站在其它人的角度尽可能清晰地、简洁地把问题描述清楚]

复现步骤
[复现问题的步骤]

  1. 使用taro-ui组件中的AtTabs和AtTabsPane,创建顶部滑动项

  2. 在AtTabsPane通过map循环创建item

  3. 如果不在第二部中添加console或者style={{}},当外层数据更新时,列表数据不会刷新

<AtTabs
   current={this.state.current}
   scroll
   tabList={this.tabList.list}
   onClick={this.handleClick.bind(this)}>
            <AtTabsPane>
              <View className="title">
                共收到{HomeSearchAllList.total}条结果
              </View>
              {resultList && resultList.length > 0 && (
                <TabList list={resultList} />
              )}
            </AtTabsPane>
</AtTabs>
export default class TabList extends Component {
  render() {
    const { list } = this.props;
    console.log("list ====> 1", list);
    return (
      <View className="contain">
        {this.props.list.map((item, index) => {
          // console.log("item ====> 2", item);
          return (
            <View className="tabItem" key={item.id} style={{}}>
                <Text className="rightIntro">{item.title}</Text>
            </View>
          );
        })}
      </View>
    );
  }
}

test

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

System:
OS: macOS 10.14.6
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.15.3 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm

补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]

@taro-bot
Copy link

taro-bot bot commented Aug 8, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@Chen-jj Chen-jj self-assigned this Aug 9, 2019
@CodeRabbitYu
Copy link
Author

import Taro, { Component } from "@tarojs/taro";
import { View, Text, Button, ScrollView } from "@tarojs/components";
import SearchInput from "./components/searchInput";
import TabList from "./components/TabList";
import { getWindowHeight } from "@utils/style";
import HistorySearch from "./components/historySearch";
import { AtTabs, AtTabsPane, AtInput, AtForm } from "taro-ui";
import "./search.scss";

import { observer, inject } from "@tarojs/mobx";
import "@tarojs/async-await";
import { HomeMobx } from "../../model/homeMobx";

@inject("userStore")
@observer
export default class Search extends Component {
  config = {
    navigationBarTitleText: "搜索"
  };
  historyContent = true;
  constructor(props) {
    super(props);
    this.state = {
      historyContent: true,
      current: 0,
      value4: "444",
      searchKey: ""
    };
    this.tabList = [
      { title: "全部" },
      { title: "视频" },
      { title: "杂志" },
      { title: "图片" },
      { title: "活动" }
    ];
    this.searchTypeArray = ["", "course", "article", "gallery", "activity"];
    this.homeMobx = new HomeMobx();
    this.AppMobx = this.props.userStore;
  }
  beginSearch = async (val, index = 0) => {
    this.setState(
      {
        historyContent: false,
        searchKey: val
      },
      async () => {
        this.historyContent = false;
        const params = {
          currentPage: 1,
          pageSize: 10,
          key: this.state.searchKey,
          type: this.searchTypeArray[index] || ""
        };
        await this.homeMobx.loadHomeSearchAllList(params);
      }
    );
  };
  clickCancel = () => {
    this.setState({
      historyContent: true
    });
    this.historyContent = true;
  };


  async componentDidMount() {
    if (!this.AppMobx.loginInstance.isLogin) {
      await this.homeMobx.loadSearchHot();
    } else {
      await this.homeMobx.loadSearchHot();
      await this.homeMobx.loadSearchAll();
    }
  }

  render() {
    const { HomesearchHot, HomeSearchAll, HomeSearchAllList } = this.homeMobx;
    return (
      <View className="searchPage">
        <SearchInput
          onSearch={val => {
            this.beginSearch(val);
          }}
          onCancel={() => {
            this.clickCancel();
          }}
        />
        <ScrollView
          scrollY
          className="home__wrap"
          style={{ height: getWindowHeight() }}
        >
          {!this.historyContent && (
            <AtTabsPane current={this.state.current} index={0}>
              <View className="title">
                共收到{HomeSearchAllList.total}条结果
              </View>
              <TabList list={HomeSearchAllList.resultList} />
            </AtTabsPane>
          )}
        </ScrollView>
      </View>
    );
  }
}

@CodeRabbitYu
Copy link
Author

CodeRabbitYu commented Aug 9, 2019

@Chen-jj 查看了diff,第二次确实没有进入diff方法中,但我在render中打印真实数据是存在的。 为什么加上空style和console就能正常呢?

@taro-bot taro-bot bot added the to be closed label Aug 9, 2019
@taro-bot
Copy link

taro-bot bot commented Aug 9, 2019

Hello~

您的问题我们无法复现。如果有空的话还请拔冗提供一个简单的复现 demo,否则这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 9, 2019

@CodeRabbitYu 在 diff 前后先打断点定位下吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants