【问题标题】:How to pass props from one component to an another component in WeChat Mini-Program如何在微信小程序中将道具从一个组件传递到另一个组件
【发布时间】:2019-06-19 05:06:06
【问题描述】:

我是微信小程序开发的新手。我来自 React Technology,我们将自定义属性 (props) 从一个组件传递到另一个组件。我试图将道具从一个组件传递到另一个组件,但在这里我失败了。请帮我如何在微信小程序中发送道具。

谢谢

第一个组件代码

    <!--index.wxml-->
<view class="container">
    <headerComponent prop-a="{{dataFieldA}}" prop-b="{{dataFieldB}}" />
</view>

第二个组件代码

    <!--components/header.wxml-->
<text>Header Component</text>
<text>{{prop-a}}</text>

我正在尝试,但prop-a 数据没有显示它给我结果NaN

【问题讨论】:

    标签: javascript reactjs wechat wechat-auth


    【解决方案1】:

    尝试使用camelCase(propA) 而不是camel-case(prop-a) 声明一个变量。

    别忘了在component.properties 中声明道具,如下所示,

    Component({
      properties: {
        propA: {
          type: String
        }
      }
    
    <text>Header Component</text>
    <text>{{propA}}</text>
    

    它应该可以工作;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2019-05-17
      • 1970-01-01
      • 2020-12-30
      • 1970-01-01
      • 2023-01-30
      • 1970-01-01
      相关资源
      最近更新 更多