「小程序JAVA实战」小程序模板在外部页面引用(20)

186 阅读1分钟

不知道老铁还有印象吗?当时讲模板的时候,是在当前的页面进行模板的应用,如何外部的方式引用模板呢?源码:github.com/limingios/w… 中的No.8

小程序的引入外部的模板

模板创建后,如何在别的页面别的地方引用。

  1. 模板在某个wxml中应以完毕后可以被其他页面引用
  2. 关键字 import
  3. A 引用B, B引用C,A不能引用C
  4. 官方的阐述

developers.weixin.qq.com/miniprogram…


  1. 演示调用外部的模板

import可以在该文件中使用目标文件定义的template。

templateImport.wxml

<import src="../templateIs/templateIs.wxml"/>
<view class="container">

  <template is="mytemp" data="{{...person,msg,name:'limng',age:'永远18岁'}}" />
  <template is="mytemp" data="{{...person,msg,name:'limng',age:'永远18岁'}}" />
  <template is="mytemp" data="{{...person,msg,name:'limng',age:'永远18岁'}}" />
</view>

templateImport.js

//templateImport.js
//获取应用实例
const app = getApp()

Page({
  data: {
    person: {
      address: "公众号:编程坑太多",
      remark: "个人主页:www.idig8.com"
    },
    msg: "感谢关注,收藏!"
  }
})

PS:这个就是使用import 针对外部文件的导入。