您现在的位置是:网站首页> 小程序设计

模块导出函数对象类

摘要

导出函数

helper.js

function generateList(count, closure) {

const list = [];

let last = {};

let current = null;

for (let i = 0; i < count; ++i) {

current = closure(i, deepCopy(last));

current = Array.isArray(current) ? current : [current]

list.push(...(deepCopy(current)));

last = deepCopy(current);

}

return list;

}


module.exports = {

sleep,

between,

toPx,

deepCopy,

generateList,

}

使用:

import {generateList,sleep} from '@/common/helper.js'

sleep(100);

导出类对象

index.js

import {generateList,sleep} from '@/common/helper.js'


class Data {

async messages() {

await sleep(300);

const list =generateList(2, () => {

return [

{

_id: '',

avatar: '/static/mock/avatars/1.jpg',

name: '大盈科技数码店',

date: '2021/01/02',

content: '你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好你好',

count: '14' //消息数量

},

{

_id: '',

avatar: '/static/mock/avatars/2.jpg',

name: '星历家纺',

date: '2021/03/02',

content: '[图片]',

count: '1' //消息数量

}

];

})

return list;

}

};


export default new Data();

使用:

import data from '@/data/index/index';


导出对象

myclass.js


var app = {


    name: 'app',


    version: '1.0.0',


    sayName: function(name){


        console.log(this.name);


    }


}


module.exports = app;

使用

import myClass from "/common/myclass.js"

var app=new myClass();

app.sayName();


上一篇:uniapp编译相关

下一篇:Promise async await

Top