Data URI
Data URI(内联数据方案)
一种URL方案,使用data:[MIME类型][;base64],<数据>格式直接在HTML、CSS或JavaScript中嵌入文件内容,无需单独的HTTP请求。
技术细节
Data URI遵循语法:data:[
示例
```javascript
// Encode string to Base64
const encoded = btoa('Hello, World!'); // 'SGVsbG8sIFdvcmxkIQ=='
// Decode Base64 to string
const decoded = atob('SGVsbG8sIFdvcmxkIQ=='); // 'Hello, World!'
// File to Base64 Data URI
const reader = new FileReader();
reader.onload = () => console.log(reader.result);
// → 'data:image/png;base64,iVBORw0KGgo...'
reader.readAsDataURL(file);
```