import API from"../../api/api.js";
 
var data = require('../../utils/data.js').songs;   //代码导出
//require 用来加载代码,而 exports 和 module.exports 则用来导出代码
module.exports = {
    songs : songs
}
 
语法
Object.keys(object)
参数
Object  : 必需。包含属性和方法的对象。这可以是您创建的对象或现有文档对象模型 (DOM) 对象
返回值:
一个数组,其中包含对象的可枚举属性和方法的名称。
keys  方法仅返回可枚举属性和方法的名称。若要返回可枚举的和不可枚举的属性和方法的名称,
 
 
module.exports = {
    getFavList: function (){
        var favList = [];
        var data = wx.getStorageSync('favlist');
        Object.keys(data).forEach(function(key){
            favList.push({
                picurl:data[key].picurl,
                name:key,
                count: data[key].list.length
            });
        });
        return favList;
    }
}
var Api = {
    //API_URL : 'http://m.api.hunantv.com/channel/getDetail',
    fetchApi : function(params) {
        var _this = this;
        return new Promise((resolve,reject) => {
            wx.request({
              url: params.API_URL,
              data:Object.assign({}, params.data),
              header: {
                'Content-Type': 'application/json'
              },
              success: resolve,
              fail: reject
            })
        })
    },
    result : function (params) {
        var _this = this;
        return _this.fetchApi(params).then( res => res)
    }
}
module.exports = Api;
使用:
// mgtv API 操作
let newData = require('../../Datas/mgtv.js’);
  onLoad: function(params){
        let _this = this;
        let param = {
            API_URL: 'http://mobile.api.hunantv.com/channel/getWPDetail',
            data:{}
        };
        newData.result(param).then( data => {
            let datas = data.data.data;
            this.setData({
                trumpArr: data.data.data,
                bg : datas[0].picUrl
            })
        }).catch(e => {
            this.setData({
                loadtxt: '数据加载异常',
                loading: false
            })
        })
    },
 
 
 

require()  module.export    Object.keys()的更多相关文章

  1. 探讨ES6的import export default 和CommonJS的require module.exports

    今天来扒一扒在node和ES6中的module,主要是为了区分node和ES6中的不同意义,避免概念上的混淆,同时也分享一下,自己在这个坑里获得的心得. 在ES6之前 模块的概念是在ES6发布之前就出 ...

  2. Error: Cannot find module '@babel/runtime/core-js/object/keys'(npm start报错)

    1.问题描述: 在npm start启动react项目的时候,会出现Cannot find module '@babel/runtime/core-js/object/keys'的报错: 打开:项目根 ...

  3. ou can mix require and export. You can't mix import and module.exports.

    ou can mix require and export. You can't mix import and module.exports.

  4. node.js中module.export与export的区别。

    对module.exports和exports的一些理解 可能是有史以来最简单通俗易懂的有关Module.exports和exports区别的文章了. exports = module.exports ...

  5. node.js module.exports & exports & module.export all in one

    node.js module.exports & exports & module.export all in one cjs const log = console.log; log ...

  6. 深入理解node.js的module.export 和 export方法的区别

    你肯定非常熟悉nodejs模块中的exports对象,你可以用它创建你的模块.例如:(假设这是rocker.js文件) exports.name = function() { console.log( ...

  7. change object keys & UpperCase & LowerCase

    change object keys & UpperCase & LowerCase .toLocaleUpperCase(); && .toLocaleLowerCa ...

  8. export、export default、module.export区别

    在es6里面定义模块,导出模块时可以使用export.export default 这2者区别: 在同一个文件里面可以有多个export, 一个文件里面只能有1个export default //a. ...

  9. ES6 模块化(Module)export和import详解 export default

    ES6 模块化(Module)export和import详解 - CSDN博客 https://blog.csdn.net/pcaxb/article/details/53670097 微信小程序笔记 ...

随机推荐

  1. pytorch1.0 安装执行后报错ImportError: No module named future.utils

    File "/usr/local/lib/python2.7/dist-packages/caffe2/python/utils.py", line 10, in <modu ...

  2. zip 格式解析

    1.格式 https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE-6.2.0.txt 官方文档 https://blog.csdn.net/hp9103 ...

  3. Python学习—数据库篇之索引

    一.索引简介 索引,是数据库中专门用于帮助用户快速查询数据的一种数据结构.类似于字典中的目录,查找字典内容时可以根据目录查找到数据的存放位置,然后直接获取即可,对于索引,会保存在额外的文件中.在mys ...

  4. python--第十五天总结(jquery)

    空格:$('parent childchild')表示获取parent下的所有的childchild节点,所有的子孙. 大于号:$('parent > child')表示获取parent下的所有 ...

  5. linux环境下安装jmeter,启动执行脚本

    1.下载安装jmeter安装包 下载链接: https://pan.baidu.com/s/1KPhwNDsmTIAy41fEopHQEw 提取码: spwd 2.上传linux平台,解压jmeter ...

  6. Huawei BGP和OSPF双边界重分布(二)

    网络拓扑: 本例主要配置和例一致,主要是在AR3260-AR1和AR3260-AR2的路由域的边界上,从AR3260-AR1上重分布进BGP 65001的路由的时候打tag 650011,在AR326 ...

  7. 贪吃蛇(简易版)Leslie5205912著

    # include <stdio.h># include <string.h># include <windows.h># include <stdlib.h ...

  8. [leetcode]272. Closest Binary Search Tree Value II二叉搜索树中最近的值2

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  9. Java并发编程:深入剖析ThreadLocal(转)

    目录大纲: 一.对ThreadLocal的理解 二.深入解析ThreadLocal类 三.ThreadLocal的应用场景 原文链接:http://www.cnblogs.com/dolphin052 ...

  10. mysql 函数介绍

    含义 一组预先编译好的SQL语句集合,可以理解成批处理语句 提高代码的重用性 简化操作 减少了编译次数并且减少了和数据库服务器的连接次数, 提高了效率 区别 : 存储过程:可以有0个返回,也可以有多个 ...