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

    在mine.wxml中定义了一个叫item的template:
      <template name="item">
        <text>{{text}}</text>
      </template>
    在detail.wxml中引用了mine.wxml,就可以使用item模板:
      <import src="../mine/mine.wxml"/>
      <template is="item" data="{{text:'设置了一些内容111'}}"></template>
 
  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 模板</text>
</template>

<!-- B.wxml -->
<import src="A.wxml">
<template name="B">
<text>B 模板</text>
</template>

<!-- C.wxml -->
<import src="B.wxml">
<template is="A"/> <!-- 报错:没有import A模板时,不能使用A模板 -->
<template is="B"/>
 
 

include

  

  include可以将目标文件除了<template/> <wxs/>外的整个代码引入,相当于是拷贝到include位置,如:
       <!-- index.wxml -->
      <include src="header.wxml"/>
      <view>body</view>
      <include src="fotter.wxml"/>

<!-- header.wxml -->
<view>header</view>

<!-- fotter.wxml -->
<view>fotter</view>

 

相关文章:

  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2021-07-16
猜你喜欢
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-09-21
  • 2021-08-10
  • 2022-01-10
  • 2021-06-26
相关资源
相似解决方案