zoukankan      html  css  js  c++  java
  • 「小程序JAVA实战」 小程序抽离公用方法进行模块化(12)

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

    小程序的模块化,把砖磊成一个墩子,用的时候把整个墩子移走。js更好的调用,应用更加公用化。源码:https://github.com/limingios/wxProgram.git 中的No.7

    小程序的模块化

    • 抽离通用方法作为通用函数
    • 构建utils-common类

    1. 官方的阐述
      >https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/module.html

    1. 程序演示

    events.js

    //events.js
    //获取应用实例
    const app = getApp()
    
    var common = require('../untils/common.js')
    
    Page({
      data: {
        motto: 'Hello World',
        userInfo: {},
        hasUserInfo: false,
        canIUse: wx.canIUse('button.open-type.getUserInfo')
      },
      clickMe: function(e){
        console.log("你点击我这里出来了!")
        console.log(e)
        console.log(e.currentTarget.dataset.fordate)
    
        common.sayHello("公众号:编程坑太多")
        common.sayGoodbye("[编程坑太多]")
      }
    })
    
    

    common.js

    // common.js
    function sayHello(name) {
      console.log(`Hello ${name} !`)
      console.log("Hello "+name+" !")
    }
    function sayGoodbye(name) {
      console.log(`Goodbye ${name} !`)
      console.log("Goodbye " + name + " !")
    }
    
    module.exports.sayHello = sayHello
    exports.sayGoodbye = sayGoodbye
    

    PS:需要注意的是

     console.log(`Goodbye ${name} !`)
     console.log("Goodbye " + name + " !")
    

    区别如果用了 ${} 最外层需要用“符号,如果你喜欢老套路可以按照我的 “Goodbye ” + name + ” !” 这种。

  • 相关阅读:
    配置Express中间件
    C#字符串中特殊字符的转义
    JSON.NET 简单的使用
    ASP.NET 解决URL中文乱码的解决
    ASP.NET MVC 笔记
    VS中一些不常用的快捷键
    Visual Studio 中突出显示的引用
    Silverlight从客户端上传文件到服务器
    silverlight打开和保存文件
    sliverlight资源文件的URI调用
  • 原文地址:https://www.cnblogs.com/sharpest/p/10272048.html
Copyright © 2011-2022 走看看