微信小程序引入方式

WXML提供两种文件引用方式

1、使用<include src="" />

include可以将目标文件除了<template/>的整个代码引入,相当于是拷贝到include位置

如:

在header.wxml中

<text>
这里是头部
</text>

在first.wxml中引入header.wxml的内容

<include src="../ttttt/header"/>
<!-- 使用include时别忘了在最后加  / -->

 

 

2、使用<import src="" />

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

如,在forter.wxml中

<template name="forter1">
这是底部1   {{text}}
</template>

<template name="forter2">
这是底部2    {{text}}
</template>

<!-- 上面是两个模板 -->

在first.wxml中引入forter.wxml的模板

<import src="../ttttt/forter"/>
<!-- 使用import时别忘了在最后加  / -->
<!-- 下面是为了确定用哪个模板 -->
<template is="forter2" data="{{text:'设置的内容'}}" />

 

注意:

import有作用域的概念,即只会import目标文件中定义的template,而不会import目标文件import的template。

如:C import B,B import A,在C中可以使用B定义的template,在B中可以使用A定义的template,但是C不能使用A定义的template

posted @ 2020-02-05 01:06  ziyuliu  阅读(417)  评论(0编辑  收藏  举报