小程序template模板import和include简单使用

微信   2025-01-06 09:19   52   0  

import 有作用域的概念,即只会 import 目标文件中定义的 template,而不会 import 目标文件 import 的 template


<!-- A.wxml -->
<template name="A">
<text> A template </text>
</template>



<!-- B.wxml -->
<import src="a.wxml"/>
<template name="B">
<text> B template </text>
</template>


<!-- C.wxml -->
<import src="b.wxml"/>
<template is="A"/> <!-- 错误不能多级引用A -->
<template is="B"/>


include 可以将目标文件除了 外的整个代码引入,相当于是拷贝到 include

<!-- index.wxml -->
<include src="header.wxml"/>
<view> body </view>
<include src="footer.wxml"/>
<!-- header.wxml -->
<view> header </view>
<!-- footer.wxml -->
<view> footer </view>


博客评论
还没有人评论,赶紧抢个沙发~
发表评论
说明:请文明发言,共建和谐网络,您的个人信息不会被公开显示。