微信小程序开发(十) - 引用外部文件 - wxml 引用
2018-03-08 08:58
543 查看
引用
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="item.wxml"/> <template is="item" data="{{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="a.wxml"/> <template name="B"> <text> B template </text> </template>
<!-- C.wxml --> <import src="b.wxml"/> <template is="A"/> <!-- Error! Can not use tempalte when not import A. --> <template is="B"/>
include
include 可以将目标文件除了<template/> <wxs/>外的整个代码引入
相当于是拷贝到 include 位置,
如:
<!-- index.wxml --> <include src="header.wxml"/> <view> body </view> <include src="footer.wxml"/>
<!-- header.wxml --> <view> header </view>
<!-- footer.wxml --> <view> footer </view>
总结来讲 ,import 用来导入 静态块 ,include 用来导入页面结构
相关文章推荐
- 在myEclipse中开发J2ME程序,引用外部jar文件的问题解决
- 【微信小程序】——wxss引用外部CSS文件及iconfont
- 微信小程序入门五: wxml文件引用、模版、生命周期
- 微信小程序入门五: wxml文件引用、模版、生命周期
- 详解微信小程序入门五: wxml文件引用、模版、生命周期
- Visual Studio如何引用外部XSD文件到XML
- 夺命雷公狗---微信开发20----编写程序进行上传多媒体文件
- 在build.xml里采用xml方式引用外部build文件
- Android程序引用外部jar时,build.xml打包脚本配置
- 3.微信小程序-B站:wxml和wxss文件
- 将Java程序打包成可执行文件jar包,然后执行jar包,不引用外部包的情况
- web.xml引用外部xml文件。以及org.xml.sax.SAXException
- 将Java程序打包成可执行文件jar包,然后执行jar包,引用外部包的情况
- Eclipse插件开发中对于外部Jar包和类文件引用的处理(彻底解决插件开发中的NoClassDefFoundError问题)
- wxfile在哪里?wx.saveFile把文件下载到计算机哪里?微信小程序开发
- 使用VC进行程序开发时,如何引用外部的库
- Eclipse 插件开发 - 实现外部程序修改文件后刷新功能
- 用extern对外部变量作提前引用声明,以扩展程序文件的作用域.Cpp
- 微信小程序WXML 数据绑定、列表渲染、条件渲染、模板、事件、引用用法
- 微信开发,对象转换为xml时候引用XStream这个类报错处理方案