转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-19/

上一节,讲了页面引用模块的概念,如果是模块之前引用呢?源码:https://github.com/limingios/wxProgram.git 中的No.8

小程序的WXS模块

  1. js代码块可以在页面中被引入使用
  2. 定义*.wxs,module.exports暴露接口和属性

    从私有到公用的概念,通过暴露就可以公有话。

  3. require函数
  4. 官方的阐述
    >https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxs/01wxs-module.html

5.演示模块之间的引用

在.wxs模块中引用其他 wxs 文件模块,可以使用 require 函数。
引用的时候,要注意如下几点:
* 只能引用 .wxs 文件模块,且必须使用相对路径。
* wxs 模块均为单例,wxs 模块在第一次被引用时,会自动初始化为单例对象。多个页面,多个地方,多次引用,使用的都是同一个 wxs 模块对象。
* 如果一个 wxs 模块在定义之后,一直没有被引用,则该模块不会被解析与运行。

wxs.wxml

<!wxs.wxml-->
<view class="container">
<wxs src="../wxs/module.wxs" module="item"></wxs>
<view>{{item.name}}</view>
<view>{{item.age}}</view>
<view>{{item.method("这是一个参数传递")}}</view> <view>{{item.name}}</view>
<view>{{item.age}}</view>
<view>{{item.method("这是一个参数传递")}}</view> <view>{{item.name}}</view>
<view>{{item.age}}</view>
<view>{{item.method("这是一个参数传递")}}</view>
</view>

module.wxs

// module.wxs
var module2 = require("../wxs/module2.wxs")
var name ="个人网站:idig8.com"
var age = 18; var method = function(obj){
console.log(module2.name);
console.log(module2.age);
return obj;
} module.exports ={
name :name,
age : age,
method :method
}

module2.wxs

// module.wxs
var name ="公众号:编程坑太多"
var age = 28; var method = function(obj){
return obj;
} module.exports ={
name :name,
age : age,
method :method
}

PS:这次就是针对模块引入模块的方式,这种在实际开发中也是很常见的。

「小程序JAVA实战」小程序模块之间引用(19)的更多相关文章

  1. 「小程序JAVA实战」小程序的flex布局(22)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...

  2. 「小程序JAVA实战」小程序模块页面引用(18)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-18/ 上一节,讲了模板的概念,其实小程序还提供了模块的概念.源码:https://github.c ...

  3. 「小程序JAVA实战」小程序的留言和评价功能(70)

    转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...

  4. 「小程序JAVA实战」小程序的举报功能开发(68)

    转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...

  5. 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...

  6. 「小程序JAVA实战」小程序的关注功能(65)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...

  7. 「小程序JAVA实战」小程序的视频点赞功能开发(62)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...

  8. 「小程序JAVA实战」小程序的springboot后台拦截器(61)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...

  9. 「小程序JAVA实战」小程序首页视频(49)

    转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...

随机推荐

  1. android 获取 图片或视频略缩图

    /** * 根据指定的图像路径和大小来获取缩略图 此方法有两点好处: 1. * 使用较小的内存空间,第一次获取的bitmap实际上为null,只是为了读取宽度和高度, * 第二次读取的bitmap是根 ...

  2. const in C/C++

    1.const 对象必须初始化,因为一旦创建后值不能改变. Eg: const int i = GetSize(); //正确:运行时初始化 const int j = 42;   //正确:编译时初 ...

  3. 《DSP using MATLAB》示例Example 6.26

    代码: % r = 0.9; theta = (pi/180)*[-55:5:-35, 35:5:55]'; p = r*exp(j*theta); a = poly(p); b = 1; % Dir ...

  4. exec 和 exec_

    exec_ 是six里面针对py2 , py3 兼容,  而做的重新定义.  和 exec 功能一样. 关键一点是:   exec 是一个语法声明,不是一个函数.  也就是说和if,for一样. ex ...

  5. pymongo和mongodbengine之间的区别

    pymongo是一个mongo driver,可以用来连接数据库以及对数据库进行操作,但是是用mongo自己的用来操作数据库的语句进行操作数据库,而mongodbengine就像是sqlalchemy ...

  6. curl 错误 [globbing] illegal character in range specification at pos

    现象 在使用curl 进行ipv6请求的时候 curl -v "http://[1:1::1]/test.html" 发生了一个错误,报错是 [globbing] illegal ...

  7. 几个开源ssg 技术方案

    1. Nanoc    2. Middle Man App   3. Hexo   4. DocPad   5. Hugo   6. Jekyll   7. Octopress   8. Harp   ...

  8. 系列文章--ASP.NET之AJAX入门教程

    ASP.NET AJAX入门系列将会写关于ASP.NET AJAX一些控件的使用方法以及基础知识,其中部分文章为原创,也有一些文章是直接翻译自官方文档,本部分内容会不断更新. 目录 ASP.NET A ...

  9. IMP-00013: 只有 DBA 才能导入由其他 DBA 导出的文件

    IMP-00013: only a DBA can import a file exported by another DBA 处理方法:在给目标环境的用户赋予dba权限,或者细粒度一些,赋予imp_ ...

  10. 微信web端生成支付二维码

    授权获取二维码类: <?php /** * Trade类 * @author xyyphp * @date 2016/10/10 */ abstract class TradeControlle ...