【...】小程序扩展运算符 ... 说明
生活随笔
收集整理的這篇文章主要介紹了
【...】小程序扩展运算符 ... 说明
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
小程序擴展運算符 ... ?,用來將一個對象展開。
以下示例:
1 <template is="objectCombine" data="{{...obj1, ...obj2, e: 5}}"></template> 1 Page({ 2 data: { 3 obj1: { 4 a: 1, 5 b: 2 6 }, 7 obj2: { 8 c: 3, 9 d: 4 10 } 11 } 12 })等同于:<template is="objectCombine" data="{{a: 1, b: 2, c: 3,d: 4, e: 5}}"></template>
?
?
對象的 key 和 value 相同,也可以間接地表達:
1 <template is="objectCombine" data="{{foo, bar}}"></template> 1 Page({ 2 data: { 3 foo: 'my-foo', 4 bar: 'my-bar' 5 } 6 })等同于:?<template is="objectCombine" data="{{foo: 'my-foo', bar: 'my-bar'}}"></template>
?
?
存在變量名相同的情況,后邊的會覆蓋前面:
1 <template is="objectCombine" data="{{...obj1, ...obj2, a: 5, c: 6}}"></template> 1 Page({ 2 data: { 3 obj1: { 4 a: 1, 5 b: 2 6 }, 7 obj2: { 8 b: 3, 9 c: 4 10 }, 11 a: 5 12 } 13 })等同于:<template is="objectCombine" data="{{a:5, b:3,c: 6}}"></template>
更多專業前端知識,請上 【猿2048】www.mk2048.com
總結
以上是生活随笔為你收集整理的【...】小程序扩展运算符 ... 说明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【WXS数据类型】Array
- 下一篇: 《React Native 精解与实战》