案例(li):微(wei)信小程(cheng)序(xu)-自(zi)定義組(zu)件(jian) 相關代碼(ma):微(wei)信小程(cheng)序(xu)自(zi)定義組(zu)件(jian)源(yuan)碼(ma) 組(zu)件(jian)化的(de)剖析過(guo)程(cheng): 注意(yi): 1. 基礎知(zhi)識:ES6 class, 參考:class 2. Object.assign() 等Object的(de)方法(fa),參考Object.assign() 具體的(de)組(zu)件(jian)化方案 ...
案例:微信小程序-自定義組件
相關代碼:微信小程序自定義組件源碼
組件化的剖析過程:
注意:
1. 基礎知識:ES6 class, 參考:class
2. Object.assign() 等Object的方(fang)法,參考Object.assign()
具體的(de)組件(jian)化(hua)方案(an)參(can)考:寫(xie)一(yi)個(ge)微(wei)信小(xiao)程(cheng)序(xu)自定義公共組件(jian)
注意的(de)是(shi):
template 使用展開的數據是 data="{{ ...obj }}",
<template is="box" data="{{...obj}}"/>
若page.data上沒有定義 obj , 在template 內使用wx:for循環(huan)輸出列表會報錯,就算(suan)在onLoad事件上setData也是有誤的。
VM18377:2 firstRender not the data from Page.datafirstRender not the data from Page.data;firstRender not the data from Page.dataError: firstRender not the data from Page.data
所以(yi)最好在data中加入一個空的obj: {}. 如果(guo)不需要用到wx:for的可以(yi)忽略(lve)。