@clayder-ran/server-log

在控制台中打印信息

Usage no npm install needed!

<script type="module">
  import clayderRanServerLog from 'https://cdn.skypack.dev/@clayder-ran/server-log';
</script>

README

发送方式

/**
 * 服务端打印
 * @param  {...(object|Array<any>)} params
 */
window.serverLog = function(...params) {
    /* 接收 对象|数组 形式的数据 */
    let data = null;
    if (params.length === 1) {
        if (typeof params[0] === "object") {
            data = params[0];
        } else {
            data = [params[0]];
        }
    } else if (params.length >= 2) {
        data = params;
    } else {
        return null;
    }

    return Taro.request({
        url: "http://192.168.1.128:3000/log",
        /* 接收地址 */
        method: "POST",
        /* 方法 */
        data,
        header: {
            "Content-Type": "application/json; charset=utf-8",
            "client-stamp": Date.now() /* 客户端时间, 用于打印排序 */
        },
        mode: "cors",
    });
};