自定义组件通过concat传入数组props,获取到空数组
发布于 6 年前 作者 ywan 16111 次浏览 来自 问答
/* index.json */
{
 
    "usingComponents": {
        "child": "../../components/Child/Child"
    }
}
 
/* index.js */
Page({
    data : {
        a : [1],
        b : [2]
    }
})
/* index.wxml */
<view>
    <child tags="{{a}}"></child>
    <child tags="{{b}}"></child>
    <child tags="{{a.concat(b)}}"></child>
</view>
 
 
//----------------------------------
 
/* Child.json */
{
    "component": true
}
/* Child.js */
Component({
    properties: {
        tags : {
            type : Array,
        }
    },
 
    ready(){
        console.log(this.data.tags);
    },
 
})

 


/* console results*/
//  [1]
//  [2]
//  []

最后的console输出的是空数组

1 回复

你好,{{ }} 中不支持绝大多数的 JS 内置对象方法,仅支持简单运算符。

回到顶部