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

prop值无法由object属性计算 #879

Closed
kdong007 opened this issue Oct 18, 2018 · 0 comments
Closed

prop值无法由object属性计算 #879

kdong007 opened this issue Oct 18, 2018 · 0 comments
Assignees

Comments

@kdong007
Copy link
Contributor

Taro 1.0.7

例如我有个测试组件

import Taro from "@tarojs/taro";
import { View } from "@tarojs/components";

export default class Test extends Taro.PureComponent {

    render() {
        const { val } = this.props;
        return <View>{val}</View>;
    }

}

在另一页面中我定义一组Constants再通过其属性计算val给Test

const Constants = {
    aa: "aa",
};

class Mypage extends Taro.Component{

   render(){
        const aa = "aa";
        return <Test val={aa === Constants.aa} />;
   }

}

这时候Test收到false
查看编译后的xml为

<test val="{{aa === Constants.aa}}" __triggerObserer="{{ _triggerObserer }}"></test>

而js没有把Constants带进去

换一些其他做法则可以正常计算:

        const aa = "aa";
        const {aa: aa2} = Constants;
        return <Test val={aa === aa2} />;
        const aa = "aa";
        const val = aa === Constants.aa;
        return <Test val={val} />;
        const aa = "aa";
        return <Test val={aa === `${Constants.aa}`} />;
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