• 「小程序JAVA实战」小程序模块之间引用(19)


    转自: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:这次就是针对模块引入模块的方式,这种在实际开发中也是很常见的。

  • 相关阅读:
    Yum 远程拒绝服务漏洞
    WordPress Simply Poll插件HTML注入和跨站请求伪造漏洞
    MySQL 和 MariaDB Geometry 查询拒绝服务漏洞
    Oracle MySQL Server/Geometry Query Processing 拒绝服务漏洞
    Linux Kernel 'cdcwdm' USB设备驱动程序堆缓冲区溢出漏洞
    Linux Kernel ext3消息记录格式化字符串漏洞
    Oracle MySQL yaSSL 不明细节缓冲区溢出漏洞
    Linux Kernel KVM 缓冲区溢出漏洞
    WordPress LeagueManager插件'league_id'参数SQL注入漏洞
    昨日关注 给控件做数字签名
  • 原文地址:https://www.cnblogs.com/sharpest/p/10277708.html
Copyright © 2020-2023  润新知