zoukankan      html  css  js  c++  java
  • 小程序-引用的两种方式:import和include

    import

      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>
  • 相关阅读:
    windows安装psycopg2问题解决方案
    error: Setup script exited with error: Unable to find vcvarsall.bat
    python web server comparison
    重置mysql root密码
    Nginx + uWSGI + web.py 搭建示例
    《凉州曲》——吴践道
    C#代理服务器
    OpenGL 分形 Sierpinski镂垫
    Chap02_递归与分治_判断两棵二叉树是否同构
    OpenGL C#绘图环境配置
  • 原文地址:https://www.cnblogs.com/wuqilang/p/12076106.html
Copyright © 2011-2022 走看看