当前位置:首页 > 小程序教程 > 小程序实战

小程序中import和include有什么区别

本篇文章给大家介绍一下微信小程序中import和include差别。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

相关学习推荐:小程序开发教程

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>


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!