Component数据传递为空?
发布于 4 年前 作者 juanzhong 8042 次浏览 来自 问答

各位好,向大家请教一个小程序使用的问题。

Page向Component传递Object类型参数,其中Number的数据无法传递,总是为null;

上图是Page完整的数据!!!

上图是Component的数据!!!

~~~~~~~~~~~~~~~~~~~~~~~~

代码如下:

Page WXML代码如下

<view class="info-unit" bindtap="onTap">
  <dtitems items="{{items}}" test="{{test}}"></dtitems>
</view>

Page JS代码如下

onTap: function() {
  this.setData({
    items: [ 
      {
        name: "马卡龙22",
        price:15,
        img:"https://d259o9es2o749h.cloudfront.net/wp-content/uploads/2018/07/09110318/128.jpg",
        min:100
      }        
    ],
    test: {
      name: "马卡龙",
      price:15,
      img:"https://d259o9es2o749h.cloudfront.net/wp-content/uploads/2018/07/09110318/128.jpg",
      min:10
    }
  });
  console.log(this.data.test)
}

Component JS代码如下

properties: {
  test: {
    type: Object,
    value: null,
    observer:function(newVal, oldVal) {  
      console.log(newVal)    
      console.log(oldVal)    
    }
  }
}

各位看官有没有碰到过,帮下小弟,多谢!

回到顶部