案例:微信小程序-自定義組件 相關(guān)代碼:微信小程序自定義組件源碼 組件化的剖析過程: 注意: 1. 基礎(chǔ)知識(shí):ES6 class, 參考:class 2. Object.assign() 等Object的方法,參考Object.assign() 具體的組件化方案 ...
案例:微信小程序-自定義組件
相關(guān)代碼:微信小程序自定義組件源碼
組件化的剖析過程:
注意:
1. 基礎(chǔ)知識(shí):ES6 class, 參考:class
2. Object.assign() 等Object的方法,參考Object.assign()
具體的組件化方案參考:寫一個(gè)微信小程序自定義公共組件
注意的是:
template 使用展開的數(shù)據(jù)是 data="{{ ...obj }}",
<template is="box" data="{{...obj}}"/>
若page.data上沒有定義 obj , 在template 內(nèi)使用wx:for循環(huán)輸出列表會(huì)報(bào)錯(cuò),就算在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
所以最好在data中加入一個(gè)空的obj: {}. 如果不需要用到wx:for的可以忽略。