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

react natvie 引用 swiper 组件 报错 undefined is not an object (evaluating 'style.height') #2301

Closed
dxhuii opened this issue Mar 1, 2019 · 5 comments
Assignees

Comments

@dxhuii
Copy link

dxhuii commented Mar 1, 2019

问题描述
[问题描述:官方 redux 模板 在 /pages/index 里面引用 swiper 组件报错]

复现步骤
官方 redux 模板 在 /pages/index 里面引用 swiper 组件报错

[或者可以直接贴源代码,能贴文字就不要截图]

import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text, Swiper, SwiperItem } from '@tarojs/components'
import { connect } from '@tarojs/redux'

import { add, minus, asyncAdd } from '@/store/actions/counter'

import './index.scss'

@connect(
  ({ counter }) => ({
    counter
  }),
  dispatch => ({
    add() {
      dispatch(add())
    },
    dec() {
      dispatch(minus())
    },
    asyncAdd() {
      dispatch(asyncAdd())
    }
  })
)
class Index extends Component {
  config = {
    navigationBarTitleText: '首页'
  }

  componentWillReceiveProps(nextProps) {
    console.log(this.props, nextProps)
  }

  componentWillUnmount() {}

  componentDidShow() {}

  componentDidHide() {}

  handleClick = url => {
    Taro.navigateTo({
      url
    })
  }

  render() {
    return (
      <View className='index'>
        <Swiper className='test-h' indicatorColor='#999' indicatorActiveColor='#333' circular indicatorDots autoplay>
          <SwiperItem>
            <Text>1</Text>
          </SwiperItem>
          <SwiperItem>
            <Text>2</Text>
          </SwiperItem>
          <SwiperItem>
            <Text>3</Text>
          </SwiperItem>
        </Swiper>
        <Button className='add_btn' onClick={this.props.add}>
          +
        </Button>
        <Button className='dec_btn' onClick={this.props.dec}>
          -
        </Button>
        <Button className='dec_btn' onClick={this.props.asyncAdd}>
          async
        </Button>
        <View>
          <Text>{this.props.counter.num}</Text>
        </View>
        <View>
          <Text>Hello, World</Text>
        </View>
        <View onClick={this.handleClick.bind(this, '/pages/top/index')}>
          <Text>去top</Text>
        </View>
      </View>
    )
  }
}

export default Index

期望行为
解决些问题

报错信息

TypeError: TypeError: undefined is not an object (evaluating 'style.height')

This error is located at:
    in _Swiper (at index.js:51)
    in RCTView (at View.js:60)
    in View (at index.js:34)
    in _View (at index.js:185)
    in _Clickable (at index.js:50)
    in RCTView (at View.js:60)
    in View (at index.js:34)
    in _View (at index.js:185)
    in _Clickable (at index.js:49)
    in Index (created by Connect(Index))
    in Connect(Index) (at index.js:35)
    in WrappedConnect (at getWrappedScreen.js:165)
    in RCTView (at View.js:60)
    in View (at ScrollView.js:791)
    in RCTScrollView (at ScrollView.js:887)
    in ScrollView (at RefreshProvider.js:18)
    in RefreshProvider (at TaroProvider.js:132)
    in TaroProvider (at getWrappedScreen.js:156)
    in WrappedScreen (at SceneView.js:9)
    in SceneView (at StackViewLayout.js:478)
    in RCTView (at View.js:60)
    in View (at StackViewLayout.js:477)
    in RCTView (at View.js:60)
    in View (at StackViewLayout.js:476)
    in RCTView (at View.js:60)
    in View (at createAnimatedComponent.js:154)
    in AnimatedComponent (at screens.native.js:59)
    in Screen (at StackViewCard.js:42)
    in Card (at createPointerEventsContainer.js:26)
    in Container (at StackViewLayout.js:507)
    in RCTView (at View.js:60)
    in View (at screens.native.js:83)
    in ScreenContainer (at StackViewLayout.js:401)
    in RCTView (at View.js:60)
    in View (at StackViewLayout.js:400)
    in StackViewLayout (at withOrientation.js:30)
    in withOrientation (at StackView.js:49)
    in RCTView (at View.js:60)
    in View (at Transitioner.js:141)
    in Transitioner (at StackView.js:19)
    in StackView (at createNavigator.js:57)
    in Navigator (at createKeyboardAwareNavigator.js:11)
    in KeyboardAwareNavigator (at createNavigationContainer.js:376)
    in NavigationContainer (at app.js:39)
    in Provider (at app.js:38)
    in App (at registerRootComponent.js:35)
    in RootErrorBoundary (at registerRootComponent.js:34)
    in ExpoRootComponent (at renderApplication.js:33)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:102)
    in RCTView (at View.js:60)
    in View (at index.js:33)
    in RootSiblingsWrapper (at AppContainer.js:119)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:122)
    in AppContainer (at renderApplication.js:32)

This error is located at:
    in NavigationContainer (at app.js:39)
    in Provider (at app.js:38)
    in App (at registerRootComponent.js:35)
    in RootErrorBoundary (at registerRootComponent.js:34)
    in ExpoRootComponent (at renderApplication.js:33)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:102)
    in RCTView (at View.js:60)
    in View (at index.js:33)
    in RootSiblingsWrapper (at AppContainer.js:119)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:122)
    in AppContainer (at renderApplication.js:32)

系统信息

  • 操作系统: [e.g. mac os 10.13.6]
  • Taro 版本 [e.g. 👽 Taro v1.2.15]
  • Node.js 版本 [e.g. v8.10.0]
  • 报错平台 [RN]
@taro-bot
Copy link

taro-bot bot commented Mar 1, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@taro-bot
Copy link

taro-bot bot commented Mar 1, 2019

CC @Pines-Cheng

@taro-bot
Copy link

taro-bot bot commented Mar 4, 2019

CC @Manjiz

@JoinGz
Copy link

JoinGz commented Mar 7, 2019

λ taro info
👽 Taro v1.2.14
Taro CLI 1.2.14 environment info:
System:
OS: Windows 10
Binaries:
Node: 10.4.1
npm: 6.1.0
同样遇到

@Manjiz Manjiz closed this as completed in 7175c03 Mar 8, 2019
@JoinGz
Copy link

JoinGz commented Mar 10, 2019

问题描述
[问题描述:官方 redux 模板 在 /pages/index 里面引用 swiper 组件报错]

复现步骤
官方 redux 模板 在 /pages/index 里面引用 swiper 组件报错

[或者可以直接贴源代码,能贴文字就不要截图]

import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text, Swiper, SwiperItem } from '@tarojs/components'
import { connect } from '@tarojs/redux'

import { add, minus, asyncAdd } from '@/store/actions/counter'

import './index.scss'

@connect(
  ({ counter }) => ({
    counter
  }),
  dispatch => ({
    add() {
      dispatch(add())
    },
    dec() {
      dispatch(minus())
    },
    asyncAdd() {
      dispatch(asyncAdd())
    }
  })
)
class Index extends Component {
  config = {
    navigationBarTitleText: '首页'
  }

  componentWillReceiveProps(nextProps) {
    console.log(this.props, nextProps)
  }

  componentWillUnmount() {}

  componentDidShow() {}

  componentDidHide() {}

  handleClick = url => {
    Taro.navigateTo({
      url
    })
  }

  render() {
    return (
      <View className='index'>
        <Swiper className='test-h' indicatorColor='#999' indicatorActiveColor='#333' circular indicatorDots autoplay>
          <SwiperItem>
            <Text>1</Text>
          </SwiperItem>
          <SwiperItem>
            <Text>2</Text>
          </SwiperItem>
          <SwiperItem>
            <Text>3</Text>
          </SwiperItem>
        </Swiper>
        <Button className='add_btn' onClick={this.props.add}>
          +
        </Button>
        <Button className='dec_btn' onClick={this.props.dec}>
          -
        </Button>
        <Button className='dec_btn' onClick={this.props.asyncAdd}>
          async
        </Button>
        <View>
          <Text>{this.props.counter.num}</Text>
        </View>
        <View>
          <Text>Hello, World</Text>
        </View>
        <View onClick={this.handleClick.bind(this, '/pages/top/index')}>
          <Text>去top</Text>
        </View>
      </View>
    )
  }
}

export default Index

期望行为
解决些问题

报错信息

TypeError: TypeError: undefined is not an object (evaluating 'style.height')

This error is located at:
    in _Swiper (at index.js:51)
    in RCTView (at View.js:60)
    in View (at index.js:34)
    in _View (at index.js:185)
    in _Clickable (at index.js:50)
    in RCTView (at View.js:60)
    in View (at index.js:34)
    in _View (at index.js:185)
    in _Clickable (at index.js:49)
    in Index (created by Connect(Index))
    in Connect(Index) (at index.js:35)
    in WrappedConnect (at getWrappedScreen.js:165)
    in RCTView (at View.js:60)
    in View (at ScrollView.js:791)
    in RCTScrollView (at ScrollView.js:887)
    in ScrollView (at RefreshProvider.js:18)
    in RefreshProvider (at TaroProvider.js:132)
    in TaroProvider (at getWrappedScreen.js:156)
    in WrappedScreen (at SceneView.js:9)
    in SceneView (at StackViewLayout.js:478)
    in RCTView (at View.js:60)
    in View (at StackViewLayout.js:477)
    in RCTView (at View.js:60)
    in View (at StackViewLayout.js:476)
    in RCTView (at View.js:60)
    in View (at createAnimatedComponent.js:154)
    in AnimatedComponent (at screens.native.js:59)
    in Screen (at StackViewCard.js:42)
    in Card (at createPointerEventsContainer.js:26)
    in Container (at StackViewLayout.js:507)
    in RCTView (at View.js:60)
    in View (at screens.native.js:83)
    in ScreenContainer (at StackViewLayout.js:401)
    in RCTView (at View.js:60)
    in View (at StackViewLayout.js:400)
    in StackViewLayout (at withOrientation.js:30)
    in withOrientation (at StackView.js:49)
    in RCTView (at View.js:60)
    in View (at Transitioner.js:141)
    in Transitioner (at StackView.js:19)
    in StackView (at createNavigator.js:57)
    in Navigator (at createKeyboardAwareNavigator.js:11)
    in KeyboardAwareNavigator (at createNavigationContainer.js:376)
    in NavigationContainer (at app.js:39)
    in Provider (at app.js:38)
    in App (at registerRootComponent.js:35)
    in RootErrorBoundary (at registerRootComponent.js:34)
    in ExpoRootComponent (at renderApplication.js:33)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:102)
    in RCTView (at View.js:60)
    in View (at index.js:33)
    in RootSiblingsWrapper (at AppContainer.js:119)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:122)
    in AppContainer (at renderApplication.js:32)

This error is located at:
    in NavigationContainer (at app.js:39)
    in Provider (at app.js:38)
    in App (at registerRootComponent.js:35)
    in RootErrorBoundary (at registerRootComponent.js:34)
    in ExpoRootComponent (at renderApplication.js:33)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:102)
    in RCTView (at View.js:60)
    in View (at index.js:33)
    in RootSiblingsWrapper (at AppContainer.js:119)
    in RCTView (at View.js:60)
    in View (at AppContainer.js:122)
    in AppContainer (at renderApplication.js:32)

系统信息

  • 操作系统: [e.g. mac os 10.13.6]
  • Taro 版本 [e.g. 👽 Taro v1.2.15]
  • Node.js 版本 [e.g. v8.10.0]
  • 报错平台 [RN]

老哥,问题解决了吗

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

5 participants