Home  >  Article  >  WeChat Applet  >  How to introduce templates into WeChat mini programs

How to introduce templates into WeChat mini programs

尚
Original
2020-03-26 16:24:144818browse

How to introduce templates into WeChat mini programs

Methods for introducing templates into WeChat mini-programs:

First method: Import through import

<!-- currency.wxml -->
<!-- 首先创建一个currency项目,里面放的是你要引入的内容 -->
<template name="shopCase">
    <view class="shopCase" wx:for="{{data}}" wx:key="{{index}}"><!-- data为自定义 接收父页面传入的数据 -->
        <text class="shopCase-price">¥{{item.price}}</text>
    </view>
</template>
<template name="howe">
  <text>在index页面,is那个name,才会引入哪个<text/>
<template/>
<!-- index.wxml -->
<import src="../components/currency/currency.wxml"/>
<!-- 在所要应用的页面导入路径 -->
<template is="shopCase" data="{{data:shoping}}"><template/>
<!-- 将js里名为shoping的数据 赋给data -->

Second method: Import through include

include can introduce the entire code of the target file except dcdc0fa59b5fea5bdae0d810c3919fcd 35ce109ec7283157c97b1ca8559eba8f

<!-- currency.wxml -->
<!-- 首先创建一个currency项目,里面放的是你要引入的内容 -->
<view class="shopCase" wx:for="{{data}}" wx:key="{{index}}">
  <text class="shopCase-price">¥{{item.price}}</text>
</view>
<template name="howe">
  <text>这个不会被引用<text/>
<template/>
<!-- index.wxml -->
<include src="currency.wxml"/><!-- 这个就相当于上面的名为shopCase的view,而不会引入template里的内容 -->

Recommended: "Small Program Development Tutorial"

The above is the detailed content of How to introduce templates into WeChat mini programs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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