美文网首页微信小程序
import和include作用域——微信小程序

import和include作用域——微信小程序

作者: JWang_小猴土豆 | 来源:发表于2016-09-25 13:43 被阅读1604次

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/>的整个代码引入,相当于是拷贝到include位置,并可嵌套引入,如:

如:C include B,B include A,等于 C include B和C。

<!-- A.wxml -->
<view> A </view>
<!-- B.wxml -->
<include src="A.wxml"/>
<view> B </view>
<!-- C.wxml -->
<include src="B.wxml"/>
<view> C </view>

相关文章

网友评论

    本文标题:import和include作用域——微信小程序

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