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

taro3 externalClasses 无效 #9037

Closed
Wkevin8 opened this issue Apr 6, 2021 · 1 comment
Closed

taro3 externalClasses 无效 #9037

Wkevin8 opened this issue Apr 6, 2021 · 1 comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@Wkevin8
Copy link

Wkevin8 commented Apr 6, 2021

相关平台

微信小程序

小程序基础库: 2.16.0
使用框架: React

复现步骤

B.tsx:

export default class B extends Component<any, any> {
  static externalClasses = ["my-class"]

  render() {
    return (<View className="my-class">111111111111</View>)
  }
}

A.tsx:

export default class A extends Component<any, any> {
  render() {
    return (<ScrollView scrollY={true}
                        scrollWithAnimation={true}
                        className={"videos-wrapper"}>
  <B my-class="red-text"/>
    </ScrollView>)
  }
}

a.scss:

.red-text {
  color: red;
}

期望结果

.red-text的color 生效到B.tsx的view上

实际结果

没有生效

环境信息

Taro CLI 3.2.0 environment info:
    System:
      OS: macOS 10.14.5
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 12.22.0 - /usr/local/bin/node
      Yarn: 1.21.1 - /usr/local/bin/yarn
      npm: 6.14.11 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.2.0 => 3.2.0
      @tarojs/mini-runner: 3.2.0 => 3.2.0
      @tarojs/react: 3.2.0 => 3.2.0
      @tarojs/runtime: 3.2.0 => 3.2.0
      @tarojs/taro: 3.2.0 => 3.2.0
      @tarojs/webpack-runner: 3.2.0 => 3.2.0
      babel-preset-taro: 3.2.0 => 3.2.0
      eslint-config-taro: 3.2.0 => 3.2.0
      react: ^17.0.0 => 17.0.2
    npmGlobalPackages:
      typescript: 3.7.3
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Apr 6, 2021
@Chen-jj
Copy link
Contributor

Chen-jj commented Apr 7, 2021

@Wkevin8 在 Taro 3 中,React 的组件 不对应 小程序自定义组件,而 externalClasses 是小程序自定义组件的功能。

你的需求按普通 React 写法即可:

// B.tsx
class B extends Component<any, any> {
  render() {
    return (
      <View className={this.props.myClass}>111111111111</View>
    )
  }
}
// A.tsx
class A extends Component<any, any> {
  render() {
    return (
      <ScrollView
        scrollY
        scrollWithAnimation
        className="videos-wrapper"
      >
        <B myClass="red-text"/>
      </ScrollView>
    )
  }
}
// a.scss
.red-text {
  color: red;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants