一夕土、學(xué)習(xí)
- 最近在學(xué)習(xí)微信小程序,遇到文件的引用問題瘟判,記下來隘弊。
二、WXML引用
1荒适、WXML引用方式
- import
- include
2、import方式
- 使用
<import src="../template/foot-menu/foot_menu.wxml"/>
<template is="footMenu"/>
說明: footMenu 就是foot_menu.wxml中的最外層標(biāo)簽
<template name="footMenu">
</template>
- import的作用域
概念:即只會import目標(biāo)文件中定義的template开镣,而不會import目標(biāo)文件import的template刀诬。
如:C import B,B import A邪财,在C中可以使用B定義的template陕壹,在B中可以使用A定義的template,但是C不能使用A定義的template树埠。
<template name="A">
<text> A template </text>
</template>
<import src="a.wxml"/>
<template name="B">
<text> B template </text>
</template>
<import src="b.wxml"/>
<template is="A"/> <!-- Error! Can not use tempalte when not import A. -->
<template is="B"/>
3糠馆、include
- include可以將目標(biāo)文件除了template的整個代碼引入,相當(dāng)于是拷貝到include位置怎憋,如:
<include src="header.wxml"/>
<view> body </view>
<include src="footer.wxml"/>
<!-- header.wxml -->
<view> header </view>
<!-- footer.wxml -->
<view> footer </view>
- 特此說明又碌,用了include的之后就可以直接不用在wxml中寫上 template這個標(biāo)簽啦
三、WXSS引用
1绊袋、wxss引用方式
- import
2毕匀、import
@import "../template/foot_menu/foot_menu.wxss"
- 特此說明:是在你要被引入的那個文件的所在的對應(yīng)的wxss中引入
- 例如:就是 index.wxml 引用了foot_menu_wxml,然后在index.wxss中引用foot_men.wxss
四癌别、總結(jié)
- 最近在學(xué)習(xí)做微信小程序皂岔,記錄一下,小伙伴有什么問題可以隨時提出啦喲展姐,大家一起學(xué)習(xí)進(jìn)步躁垛。