转自: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. cocos2d-x 发布win32 release版本后找不到msvcr110.dll

    解决方法: 安装Visual C++ Redistributable for Visual Studio 2012 //下载地址 http://www.microsoft.com/zh-CN/down ...

  2. ios PageControl and UIScrollView

    // //  AlbumViewController.m //  HwangKop08.18 // //  Created by rimi on 15/8/20. //  Copyright (c) ...

  3. ios 延迟调用 && UIImageView && UILabel && UISegmentedControl && UISwitch && UISlider

    // //  ViewController.m //  UI_Lesson3 // //  Created by archerzz on 15/8/13. //  Copyright (c) 2015 ...

  4. 《DSP using MATLAB》示例Example 8.25

  5. pipeline的存储代码

    在spider中最后一个函数返回item时会scrapy会调用pipeline里面的 process_item(self, item, spider):函数并传入item,spider等参数在这里可以 ...

  6. 小波分解和合成的simulink仿真

    采用5-3提升小波的方法 小波分解 数据拆分 预测 更新 数据输出使能电路 电路共有两个输入三个输出,in1是数据输入,in2是输入数据有效信号,out1是更新后的低频信号,out2是预测的高频信号, ...

  7. YARN的Fair Scheduler和Capacity Scheduler

    关于Scheduler YARN有四种调度机制:Fair Schedule,Capacity Schedule,FIFO以及Priority: 其中Fair Scheduler是资源池机制,进入到里面 ...

  8. bzoj 4815 [Cqoi2017]小Q的表格——反演+分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4815 大概就是推式子的时候注意有两个边界都是 n ,考虑变成 2*... 之类的. 分块维护 ...

  9. 读取设置config.ini配置

    class CSenseIni { /************************************************************************/ /*写操作 * ...

  10. Linux 文件系统目录结构

    进入 Linux 根目录(即 "/",Linux文件系统的入口,也是处于最高一级的目录),运行 "ls -l" 命令,可以看到 Linux 系统目录. 1./b ...