[Javascript] Format console.log with CSS and String Template Tags

本文介绍如何使用CSS属性在Chrome控制台中格式化日志消息,通过示例展示了如何利用自定义样式来增强日志的可读性,并提供了一种使用模板标签函数的方法以提高格式化的复用性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The Chrome console allows you to format messages using CSS properties. This lesson walks you through the syntax of formatting your logs with css then refactoring into a template tag function to make formatting more reusable.

 

const debug = (label, style, obj) => {
    console.log(`%c${label}`, `${style}`, `${obj}`);
};

debug(
    `debug: `,
    `color: white; background-color: grey; padding: 0 0.5em;`,
    JSON.stringify({name: 'Zhentian'}));

 

转载于:https://www.cnblogs.com/Answer1215/p/6358904.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值