小程序 · 2023年6月11日

微信小程序怎么引入模板

微信小程序引入模板的方法:

第一种:通过import引入

<!-- currency.wxml -->
<!-- 首先创建一个currency项目,里面放的是你要引入的内容 -->
<template>
    <view><!-- data为自定义 接收父页面传入的数据 -->
        <text>¥{{item.price}}</text>
    </view></template><template>
  <text>在index页面,is那个name,才会引入哪个<text></text><template></template></text></template>

登录后复制

<!-- index.wxml -->
<import></import><!-- 在所要应用的页面导入路径 --><template><template></template><!-- 将js里名为shoping的数据 赋给data --></template>

登录后复制

第二种:通过include导入

include 可以将目标文件除了 外的整个代码引入

<!-- currency.wxml -->
<!-- 首先创建一个currency项目,里面放的是你要引入的内容 -->
<view>
  <text>¥{{item.price}}</text></view><template>
  <text>这个不会被引用<text></text><template></template></text></template>

登录后复制

<!-- index.wxml -->
<include></include><!-- 这个就相当于上面的名为shopCase的view,而不会引入template里的内容 -->

登录后复制

推荐:《》

以上就是微信小程序怎么引入模板的详细内容,更多请关注GTHOST其它相关文章!