📦 安装
bash
pnpm add buzztsbash
yarn add buzztsbash
npm install buzzts📡 CDN
html
<script src="//cdn.jsdelivr.net/npm/buzzts"></script>html
<script src="//unpkg.com/buzzts"></script>js
// 使用 fetch 动态引入 buzzts 库
fetch('https://cdn.jsdelivr.net/npm/buzzts@latest')
.then(response => response.text())
.then(scriptText => {
const script = document.createElement('script');
script.textContent = scriptText;
document.head.appendChild(script);
// 确保 buzzts 已加载并且 randColorHEX 可用
if (typeof buzzts.randColorHEX === 'function') {
console.log('随机颜色:', buzzts.randColorHEX());
} else {
console.error('randColorHEX 函数未定义');
}
})
.catch(error => console.error('加载脚本失败:', error));html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>引入 buzzts 示例</title>
</head>
<body>
<h1>欢迎使用 buzzts</h1>
<!-- 引入 buzzts 库 -->
<script src="https://cdn.jsdelivr.net/npm/buzzts@latest"></script>
<script>
// 等待文档加载完成
window.onload = function() {
// 确保 buzzts 已加载并且 randColorHEX 可用
if (typeof buzzts.randColorHEX === 'function') {
console.log('随机颜色:', buzzts.randColorHEX());
} else {
console.error('randColorHEX 函数未定义');
}
};
</script>
</body>
</html>🤔 常见问题、反馈
问题:如果自己项目中的函数与 buzzts 内部的函数名称冲突怎么办?
答:这种问题很常见,可以使用 ES6 提供的 as 关键字来为导入的函数重命名,如下:
ts
import { deepClone as _deepClone } from "buzzts";
_deepClone(xxx);🔔 温馨提示
本站大部分图片使用Github静态资源。如遇加载空白或加载图片失败时,刷新几次即可