美文网首页
小程序之引用

小程序之引用

作者: yiyididi | 来源:发表于2018-11-28 22:58 被阅读0次

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

在helloworld.wxml中定义了一个叫msgItem和item的tempalte:

<template name="msgItem">

<view>

<text>{{index}}:{{msg}}</text>

<text>Time:{{time}}</text>

</view>

</template>

<template is="msgItem" data="{{...item}}"/>

<template name="item">

<text>{{text}}</text>

</template>

在index.wxml中引用了helloworld.wxml,就可以使用helloworld.wxml.wxml模板

<import src="/pages/helloworld/helloworld.wxml"/>

<template is="msgItem" data="{{...item}}" />

<template is="item" data="{{text:'forbar'}}" />

另外需要注意:

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

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

运行结果:

相关文章

网友评论

      本文标题:小程序之引用

      本文链接:https://www.haomeiwen.com/subject/amjtcqtx.html