「小程序JAVA实战」小程序模块之间引用(19)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-19/
上一节,讲了页面引用模块的概念,如果是模块之前引用呢?源码:https://github.com/limingios/wxProgram.git 中的No.8
小程序的WXS模块
- js代码块可以在页面中被引入使用
定义*.wxs,module.exports暴露接口和属性
从私有到公用的概念,通过暴露就可以公有话。
- require函数
- 官方的阐述
>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)的更多相关文章
- 「小程序JAVA实战」小程序的flex布局(22)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...
- 「小程序JAVA实战」小程序模块页面引用(18)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-18/ 上一节,讲了模板的概念,其实小程序还提供了模块的概念.源码:https://github.c ...
- 「小程序JAVA实战」小程序的留言和评价功能(70)
转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...
- 「小程序JAVA实战」小程序的举报功能开发(68)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...
- 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...
- 「小程序JAVA实战」小程序的关注功能(65)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...
- 「小程序JAVA实战」小程序的视频点赞功能开发(62)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...
- 「小程序JAVA实战」小程序的springboot后台拦截器(61)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...
- 「小程序JAVA实战」小程序首页视频(49)
转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...
随机推荐
- WPF 应用完全模拟 UWP 的标题栏按钮
WPF 自定义窗口样式有多种方式,不过基本核心实现都是在修改 Win32 窗口样式.然而,Windows 上的应用就应该有 Windows 应用的样子嘛,在保证自定义的同时也能与其他窗口样式保持一致当 ...
- Python: 为对象动态添加函数,且函数定义来自一个str
转自:http://blog.sina.com.cn/s/blog_55a11f330100ab1x.html 在Python中,通常情况下,你只能为对象添加一个已经写好的方法 需求:传入一个str类 ...
- vb编写串口调试程序
sub是子模块,可以调用但是没有返回值,function是有返回值的. public sub 可以在其它form里调用,而private sub 只能在当前form里调用. vb里的if else , ...
- Python 三元条件判断表达式(and or/if else)
参考: http://wangye.org/blog/archives/690/
- 错误:Authentication with old password no longer supported, use 4.1 style passwords.
今天重新装了系统,mysql connector 使用了官网的最新版本(6.8.3). 启动项目出现标题中的错误.原因大家谷歌. 解决方法,使用低版本的 connector. 我使用的是 6.5.6 ...
- centos下svn的主要常用命令(解决商城系统添加的文件无法自动更新至svn服务器)
问题描述: 在商城中通过网页上传的png文件无法自动添加到版本库中. 查找过程: 通过程序分析,增加的主要是数据文件,主要分布在data目录中. svn list /home/ggg --depth= ...
- dwr的A request has been denied as a potential CSRF attack.错误
虽然DWR是个很早就出现的Ajax框架,但一直都没去使用过,今天正好没事就看了一下并参照文档照做了个demo, 在其中碰到一个问题: 后台打印出错误信息:“严重: A request has been ...
- SQLServer中求两个字符串的交集(字符串以符号分隔)
两个字符串,以特定符号分隔(例如‘,’号),求交集 第一种情况: declare @m varchar(100),@n varchar(100)select @m=',2,3,5,7,8,9,10,' ...
- OpenCV在debug和release模式下选择不同的lib静态库文件
这两天测试OpenCV显示到MFC的Picture控件上,终于测试成功了,但是换到release模式下就会imread失败.发现问题是导入的lib问题. 因为VS如果通过Property Manage ...
- mybatis 面试
1.接口绑定有几种实现方式,分别是怎么实现的? 接口绑定有两种实现方式,一种是通过注解绑定,就是在接口的方法上面加上 @Select@Update等注解里面包含Sql语句来绑定, 另外一种就是通过xm ...