受欢迎的博客标签

wechat-微信小程序Asp .Net Core开发实战记录(18)-module.exports 模块化

Published

微信小程序引入其它js的方法,使用require和import的区

https://segmentfault.com/q/1010000015690715

微信小程序: module.exports &require----业务中的数据分离

https://blog.csdn.net/hxfghgh/article/details/80641547

 

step 1.写一个模块

config.js

代码:

//小程序module.exports 模块化
/**
 * 配置集合名称
 **/
var friendsCircleCollection = 'friendsCircle';


//模块化
module.exports = {
  friendsCircleCollection: friendsCircleCollection
}

 

step 2:引用模块

// miniprogram/pages/friendsCircle/index/index.js
//朋友圈项目:https:/ / github.com / xiaozhaoqi / moments

var config = require("../modules/config.js")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: false,
    bgiURL: '',
    avatarUrl: '',
    nickName: '',
    text: '',
    page: 1,
    pageSize: 10,
    hasMoreData: true,
    stateList: [],
    showMenu: [],
    formImageId: '',
    imageStamp: 0,
    submitDisabled: false,
    friendsCircleCollection: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    
    this.setData({
      friendsCircleCollection: config.friendsCircleCollection
    });

  },

 

结果如下

 

业务数据分离

/ models/Customer/Customer.js
//https://blog.csdn.net/hxfghgh/article/details/80641547?utm_medium=distribute.wap_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.wap_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase
{
  var Customer =
  {
    Appid: "",
    Unionid: "",
    Openid: "",
    AuthorOpenid: "",

    UserInfo: {},

    UserName: "",
    TelephoneNumber: "",

    EmployeeRoles: {}, //员工角色
    Level: 0,  //权限级别
    ShopRoles: {}, //员工角色
    IsEmployee: false, // 是否员工
    IsAdmin: false, // 是否员工
    IsAuthorized: false, // 是否已取得授权

    Approved: false, // 是否员工 -批准


    CreatedOnUtc: new Date(),
    UpdatedOnUtc: new Date(),
    LastloginOntUtc: new Date(),
  }

  // 导出模块
  module.exports = {
    Customer: Customer,
  }
}