1.前言爹脾,其實(shí)在微信小程序中不管是pages、template箕昭、component都可以稱為組件灵妨,只是大小不一樣而已,為了提高效率落竹,我們可以將組件進(jìn)行封裝復(fù)用泌霍。
2.template,component兩個(gè)組件的區(qū)別有,template組件一般用于展示頁(yè)面述召,對(duì)于需要復(fù)雜的父子組件邏輯很難處理朱转,
由于沒(méi)有js文件,而compon和pages有四個(gè)基本文件积暖,可以父子組件傳值藤为,處理不同父子組件的邏輯沒(méi)有沖突。
3.用法:template:3.1建立template.wxml,template.wxss文件夺刑,3.2在template文件中進(jìn)行命名name=xxx,3.3在需要引用的地方導(dǎo)入<import src="url"/> <template is="xxx" data="{{json數(shù)據(jù)}}"></template>?
component:3.1建立compnent文件? ?3.2引用"usingComponents": {
? ? "Header":"../../components/Header/Header",
? ? "Footer":"../../components/footer/footer"
? }缅疟,3.3傳值? 首先在子組件中的properties定義屬性data{type,value} 在父組件中和子組件屬性同名data="{{數(shù)據(jù)}}"