美文网首页
自定义组件 component

自定义组件 component

作者: 方_糖 | 来源:发表于2019-01-25 11:21 被阅读0次

一.用properties从页面传递参数给组件

  • 1.定义参数paramA,参数类型为String(component/component.js)
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    paramA:String
  },
...
})
  • 2.在调用组件时传递参数 paramA
    (index/index.json):首先在json文件中引入组件
"usingComponents": {
    "mycomponent ":"/component/component",
  }

(index/index.wxml): 然后在wxml文件中使用组件

<mycomponent paramA="type-01"></mycomponent>
    1. 使用传递过来的参数(component/component.js)
this.data.paramA
补充说明

这里除了在组件中直接在<mycomponent paramA="type-01"></mycomponent>传递参数外,还可以通过json中引入组件时传递参数,如
index/index.json

"usingComponents": {
    "mycomponent ":"/component/component?param=type-01",
  }

参考地址 :https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html

相关文章

网友评论

      本文标题:自定义组件 component

      本文链接:https://www.haomeiwen.com/subject/fhrydqtx.html