组件json文件

{
  "usingComponents": {},
  "component": true
}

组件js文件

Component({
  data: {
    value: 1
  },
  properties:{
      innreTest:{
        type:'String',
      value:'123123'
      },
      dataArr:{
        type:'Array',
        value:[]
      }
  },

  methods: {
    closeDialog() {
      this.triggerEvent('closedialog', {})
    },
    chooseItem(e){
      // console.log(e.currentTarget.dataset.item)
      let item = e.currentTarget.dataset.item
      this.triggerEvent('choose',item)
    }
  },
  addnum() {
    this.data.value ++
    this.triggerEvent('addnum', {})
  },


})

组件xwml文件

<!--components/test/test.wxml-->
<view class="testmodel" >
  <view class="flex">
      {{innreTest}}
    <text catchtap="closeDialog">取消</text>
    <text catchtap="addnum">确定</text>
    <text wx:for="{{dataArr}}" bindtap="chooseItem" data-item="{{item}}">{{item.name}}</text>
  </view>
</view>

使用组件

<test  dataArr="{{dataArray}}" bindchoose="fuchoose" innre-test="{{innreTest}}"></test>

js data

 dataArray:[{
      name:'张三'
    },
    {
      name:'李四'
    }],
    innreTest:'ettrytrt',
    methods:{
      fuchoose(e){
            console.log(e.detail.name);//张三李四~~~~
  },
    }

疯狂程序猿
4 声望1 粉丝

理论+实践 分享生活