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

组件继承中部分 methods 不可用 #563

Closed
ly525 opened this issue Sep 2, 2018 · 2 comments
Closed

组件继承中部分 methods 不可用 #563

ly525 opened this issue Sep 2, 2018 · 2 comments
Assignees

Comments

@ly525
Copy link
Contributor

ly525 commented Sep 2, 2018

问题描述

有Parent 组件,有方法 switchTabonShareAppMessage 方法,在 class Child extends Parent 之后,onShareAppMessage 是可以正常调用的,但是 switchTab 无法调用

复现步骤

import Taro, { Component } from '@tarojs/taro'

export default class Parent extends Component {
    // ---- common methods start -------
    cardClick = () => {
       debugger
    }
    switchTab = (index, e)  => {
      this.setState({
        current: index
      })
    }

    onShareAppMessage = (res) => {
      if (res.from === 'button') {
        // 来自页面内转发按钮
        console.log(res.target)
      }
      return {
        title: 'title',
        path: getCurrentPageUrlWithArgs(),
      }
    }

    // common methods end
}

import Taro, { Component } from '@tarojs/taro'
import { AtTabs, AtTabsPane } from 'taro-ui'

import Parent from './parent'

export default class Child extends Parent {
  constructor() {
    super(...arguments)
    this.state = {
      tabList: [
        { title: '列表' },
        { title: '地图' },
        { title: '基本信息' }
      ],
      current: 0,
    };
  }

  render() {
    let { current, } = this.state
    return (
     <View>
      {/* tabs start */}
      <AtTabBar
        fixed
        tabList={[
          { title: '学校列表', iconType: 'list', },
          { title: '地图', iconType: 'map-pin',},
          { title: '简介', iconType: 'streaming', },
        ]}
        onClick={this.switchTab}
        current={current}
      />
      {/* tabs end */}
     <AtCard
	extra='详情'
	title='title'
	thumb='http://xxx.PNG'
	onClick={this.cardClick}
	>
      </AtCard>
     </View>
    )
  }
}

期望行为
希望其他方法也能被正常调用

报错信息

[这里请贴上你的完整报错截图或文字]
image

系统信息

  • 操作系统: osx
  • Taro 版本 v1.0.0-beta.22
  • Node.js 版本 v8.4.0
@SzHeJason
Copy link

SzHeJason commented Sep 11, 2018

@yuche 如果绑定的事件来自父类,这里编译后就会缺少 __fn_onXxx=true

image

@SzHeJason SzHeJason reopened this Sep 11, 2018
@ldwonday
Copy link

使用属性的方式定义方法:a = () => {}

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