taro icon indicating copy to clipboard operation
taro copied to clipboard

存在将未绑定在 WXML 的变量传入 setData

Open ruixiu opened this issue 8 years ago • 8 comments

问题描述 按照官方收录的文章教程《从0到1构建适配不同端(微信小程序、H5、React-Native 等)的taro + dva应用》引入了dva,在使用微信开发者工具的Audits进行体验分析的时候,得出“存在将未绑定在 WXML 的变量传入 setData”的问题。请问直接使用redux是否也存在类似情况????

复现步骤 个人验证只有在使用dva的时候才会出现,直接使用官方在page类中直接setState是没有的

ruixiu avatar Oct 10 '18 02:10 ruixiu

使用 redux 不存在此问题,按理来说 dva 也一样,你可以先自行排查一下

luckyadam avatar Oct 10 '18 02:10 luckyadam

经过验证,如图,在显示 首页 的时候没有提示,由首页切换到 我的 之后,会显示首页的变量 “存在将未绑定在 WXML 的变量传入 setData”。

image

ruixiu avatar Oct 10 '18 02:10 ruixiu

import Taro, { Component } from '@tarojs/taro'
import { View, Text, Swiper, SwiperItem, Image, ScrollView } from '@tarojs/components'

import './index.scss'

export default class Index extends Component {

  constructor(props) {
    super(props);

    this.state = {
      banner: [],
      channel: [],
      brandList: [],
      newGoods: [],
      hotGoods: [],
      topicList: [],
      newCategoryList: [],
    }
  }

  config = {

  }

  async componentWillMount () {
    let {banner, channel, brandList, newGoods, hotGoods, topicList, newCategoryList} = await Taro.$http.get('/index/index');
    this.setState({
      banner,
      channel,
      brandList,
      newGoods,
      hotGoods,
      topicList,
      newCategoryList,
    })
  }

  goodsDetail(id) {
    Taro.navigateTo({
      url: `/pages/goods/index?id=${id}`
    })
  }
  categoryList(id) {
    Taro.navigateTo({
      url: `/pages/categorylist/index?id=${id}`
    });
  }
  goodsList(info) {
    if (info === 'hot') {
      Taro.navigateTo({
        url: '/pages/newgoods/index?isHot=1'
      });
    } else {
      Taro.navigateTo({
        url: '/pages/newgoods/index?isNew=1'
      });
    }
  }
  topicdetail(id) {
    Taro.navigateTo({ url: `/pages/topicdetail/index?id=${id}`});
  }
  totopic() {
    Taro.navigateTo({ url: '/pages/topic/index' });
  }
  tobrandList() {
    Taro.navigateTo({ url: '/pages/brandlist/index' });
  }
  branddetail(id) {
    Taro.navigateTo({ url: `/pages/branddetail/index?id=${id}` });
  }

  render () {
    return (
      <View className='index'>
        <View className='swiper'>
          <Swiper className='swiper-container' indicatorDots autoplay interval='3000' circular duration='500'>
            {
              this.state.banner.map(item =>
                <SwiperItem className='swiper-item' key={item.id}>
                  <Image src={item.image_url} className='slide-image' />
                </SwiperItem>
              )
            }
          </Swiper>
        </View>
        <View className='channel'>
          {
            this.state.channel.map(item =>
              <View onClick={this.categoryList.bind(this, item.id)} key={item.id}>
                <Image src={item.icon_url} />
                <Text>{item.name}</Text>
              </View>
            )
          }
        </View>
        <View className='brand'>
          <View className='head'>品牌制造商直供</View>
          <View className='content'>
            {
              this.state.brandList.map(item =>
                <View key={item.id}>
                  <View>
                    <Text>{item.name}</Text>
                    <Text>{item.floor_price}元起</Text>
                  </View>
                  <Image src={item.new_pic_url} />
                </View>
              )
            }
          </View>
        </View>
        <View className='newgoods'>
          <View className='newgoods-top'>
            <View className='top'>
              <Text>新品首发</Text>
              <Text>查看全部</Text>
            </View>
          </View>
          <View className='list'>
            <View>
              <ScrollView className='scroll-view' scrollX>
                {
                  this.state.newGoods.map(item =>
                    <View key={item.id}>
                      <View>
                        <Image src={item.list_pic_url} />
                        <Text>{item.name}</Text>
                        <Text>{item.goods_brief}</Text>
                        <Text>¥{item.retail_price}</Text>
                      </View>
                    </View>
                  )
                }
              </ScrollView>
            </View>
          </View>
        </View>
        <View className='newgoods hotgoods'>
          <View className='newgoods-top'>
            <View className='top'>
              <Text>人气推荐·好物精选</Text>
              <Text>查看全部</Text>
            </View>
          </View>
          <View className='list'>
            <View>
              <ScrollView className='scroll-view' scrollX>
                {
                  this.state.hotGoods.map(item =>
                    <View key={item.id}>
                      <View>
                        <Image src={item.list_pic_url} />
                        <Text>{item.name}</Text>
                        <Text>{item.goods_brief}</Text>
                        <Text>¥{item.retail_price}</Text>
                      </View>
                    </View>
                  )
                }
              </ScrollView>
            </View>
          </View>
        </View>
        <View className='topicList'>
          <View className='topicList-top'>
            专题精选
            <Text className='icon'></Text>
          </View>
          <View className='list'>
            <View>
              <ScrollView className='scroll-view' scrollX>
                {
                  this.state.topicList.map(item =>
                    <View key={item.id}>
                      <Image src={item.item_pic_url} />
                      <View className='btom'>
                        <View>
                          <Text>{item.title}</Text>
                          <Text>{item.subtitle}</Text>
                        </View>
                        <Text className='price'>
                          {item.price_info}元起
                        </Text>
                      </View>
                    </View>
                  )
                }
              </ScrollView>
            </View>
          </View>
        </View>
        <View className='newcategory'>
          {
            this.state.newCategoryList.map(item =>
              <View key={item.id}>
                <View className='head'>{item.name}好物</View>
                <View className='sublist'>
                  {
                    item.goodsList.map(subitem =>
                      <View key={subitem.id}>
                        <Image src={subitem.list_pic_url} />
                        <View>
                          <Text>{subitem.name}</Text>
                          <Text>¥{subitem.retail_price}</Text>
                        </View>
                      </View>
                    )
                  }
                  <View>
                    <View className='last'>
                      <Text>{item.name}好物</Text>
                      <Text className='icon'></Text>
                    </View>
                  </View>
                </View>
              </View>
            )
          }
        </View>
      </View>
    )
  }
}

ruixiu avatar Oct 10 '18 02:10 ruixiu

下图是官方提供的taro-zhihu-sample的结果,不知道对小程序性能会不会有影响

1539140452976

ruixiu avatar Oct 10 '18 03:10 ruixiu

好~ 我看看这个问题

luckyadam avatar Oct 10 '18 03:10 luckyadam

我发现绑定的变量,值没有变更的时候也会setData到视图层(该实验是通过taro-ui的toast组件,将其isOpened属性值放到redux管理,试出来的。当将isOpened在redux中变更为true,toast消失后,每次改变其他页面绑定变量,也会导致toast显示)

Andrewuetyang avatar Feb 26 '19 01:02 Andrewuetyang

好~ 我看看这个问题

这个问题目前有计划么,或者什么解决的方向?~

Miantang avatar May 20 '19 09:05 Miantang

Taro 3 是最小颗粒度的 setData,应该没有这个问题了

Chen-jj avatar Jul 02 '20 06:07 Chen-jj