首页 技术 正文
技术 2022年11月8日
0 收藏 673 点赞 1,373 浏览 1264 个字

系列文章:

微信小程序 教程之WXSS
微信小程序 教程之引用
微信小程序 教程之事件
微信小程序 教程之模板
微信小程序 教程之列表渲染
微信小程序 教程之条件渲染
微信小程序 教程之数据绑定
微信小程序 教程之WXML

引用

WXML提供两种文件引用方式import和include。
import

import可以在该文件中使用目标文件定义的template,如:
在item.wxml中定义了一个叫item的template:
<!– item.wxml –>
<template name=”item”>
<text>{{text}}</text>
</template>
在index.wxml中引用了item.wxml,就可以使用item模板:
<import src=”http://1219.www.qixoo.qixoo.com/article/item.wxml”/>
<template is=”item” data=”http://qkxue.net/article/{{text:’forbar’}}”/>
import的作用域

import有作用域的概念,即只会import目标文件中定义的template,而不会import目标文件import的template。
如:C import B,B import A,在C中可以使用B定义的template,在B中可以使用A定义的template,但是C不能使用A定义的template。
<!– A.wxml –>
<template name=”A”>
<text> A template </text>
</template>
<!– B.wxml –>
<import src=”http://1219.www.qixoo.qixoo.com/article/a.wxml”/>
<template name=”B”>
<text> B template </text>
</template>
<!– C.wxml –>
<import src=”http://1219.www.qixoo.qixoo.com/article/b.wxml”/>
<template is=”A”/> <!– Error! Can not use tempalte when not import A. –>
<template is=”B”/>
include

include可以将目标文件出了<template/>的整个代码引入,相当于是拷贝到include位置,如:
<!– index.wxml –>
<include src=”http://1219.www.qixoo.qixoo.com/article/header.wxml”/>
<view> body </view>
<include src=”http://1219.www.qixoo.qixoo.com/article/footer.wxml”/>
<!– header.wxml –>
<view> header </view>
<!– footer.wxml –>
<view> footer </view>
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295