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

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

青灯夜游
Release: 2021-07-20 17:25:58
forward
3774 people have browsed it

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>
Copy after login
<!-- B.wxml -->
<import src="a.wxml"/>
<template name="B">
  <text> B template </text>
</template>
Copy after login
<!-- C.wxml -->
<import src="b.wxml"/>
<template is="A"/>  <!-- 错误不能多级引用A -->
<template is="B"/>
Copy after login

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"/>
Copy after login
<!-- header.wxml -->
<view> header </view>
Copy after login
<!-- footer.wxml -->
<view> footer </view>
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template