Home  >  Article  >  WeChat Applet  >  What is the difference between import and include in a mini program?

What is the difference between import and include in a mini program?

青灯夜游
青灯夜游forward
2021-05-24 11:23:213630browse

This article will introduce to you the difference between import and include in WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

What is the difference between import and include in a mini program?

Related learning recommendations: Small Program Development Tutorial

import has the concept of scope, that is, it will only import the definitions in the target file The template of import will not import the target file. The template of import

<!-- 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 can introduce the entire code except the target file, which is equivalent to copying to include

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

For more programming-related knowledge, please Visit: Introduction to Programming! !

The above is the detailed content of What is the difference between import and include in a mini program?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete