的data="{{...">
美文网首页
小程序中data="{{...item}}"中...的作用

小程序中data="{{...item}}"中...的作用

作者: 一枚倔强的程序员 | 来源:发表于2019-09-26 16:23 被阅读0次

下面代码中<template is="msgItem" data="{{...item}}"/>的data="{{...item}}"是什么意思呢?

//js代码
<!--
item: {
  index: 0,
  msg: 'this is a template',
  time: '2016-06-18'
}
-->


//wxml代码
<template name="msgItem">
  <view>
    <text> {{index}}: {{msg}} </text>
    <text> Time: {{time}} </text>
  </view>
</template>


<template is="msgItem" data="{{...item}}"/>

<!-- 输出
0: this is a template Time: 2016-06-18
-->

data="{{...item}}"中的...是ES6中的扩展运算符,该运算符主要用于函数调用,在这里的作用是调用了name=msgItem的模板。