"JAVA applet real" applets using the common template (17)

Applet also adds the ability to page generic template, how to understand a generic template it? Custom template is to allow our page to enjoy some common words of templates that can be us as a general method js inside defined, when we need these generic template, you only need to call these templates can be, and templates are also provided Some parameters. Source: https: //github.com/limingios/wxProgram.git in No.8

Applet to define a generic page template

  1. template name =”[templateName]”

  2. Reference template is = [templateName]

  3. Incoming parameter data = {{data}}

  4. The official explained
    > https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/template.html

  1. The concept of the presentation template
    > WXML provides a template (template), you can then call in a different place in the defined template code snippets.
    Use the name attribute as the name of the template. Then in template code snippet within the definition, is the use of property, the statement needed to use a template, the template will then pass the required data, the template has its own scope, you can only use the data as well as incoming data template definition file definitions module.

templateIs.wxml

<!templateIs.wxml-->
<template name="mytemp">
  <view>姓名:{{name}}</view>
  <view>年龄:{{age}}</view>
  <view>地址:{{address}}</view>
  <view>备注:{{remark}}</view>
  <view>msg:{{msg}}</view>
</template>

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

templateIs.js

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

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

PS:应该是随着开发小程序项目的增多,肯定会积累一些代码,这些代码都可以通过抽离template的方式来方面后期的开发。



Guess you like

Origin blog.51cto.com/12040702/2424419
Recommended