# streamMixin
# Feature Description
Provides SSE (Server-Sent Events) data parsing and interruption capabilities, supporting the following features:
- Supports parsing and processing of SSE data streams
- Supports interruption control for streaming requests
- Automatically handles stream data status
- Error handling mechanism
- Supports custom transform streams
# Import and Usage
import { streamMixin } from 'vue-element-ui-x';
export default {
mixins: [streamMixin],
// ...
};
Note
The import method in the following example is to resolve an error during the documentation site's packaging. Under normal circumstances, please import it in the standard way.
# Usage Examples
# SSE Stream Data Example
Demonstrates how to handle SSE stream data and display Markdown content in the Bubble component.
Copy
# SIP Protocol Data Handling Example
Demonstrates how to handle SIP protocol stream data and use a custom transform stream.
Copy
# Mixin Properties
| Parameter | Description | Type | Default |
|---|---|---|---|
| streamData | Stream data array | Array | [] |
| streamError | Stream error info | Error | null |
| streamLoading | Stream processing status | Boolean | false |
# Mixin Methods
| Method Name | Description | Parameters | Return Value |
|---|---|---|---|
| startStream | Starts a streaming request | options: { readableStream, transformStream } | Promise |
| cancelStream | Cancels the streaming request | - | - |
| resetStream | Resets the stream state | - | - |
| createStreamProcessor | A utility method to create a stream processor | readableStream, transformStream | Object |
# Events
| Event Name | Description | Callback Parameter |
|---|---|---|
| stream-data | Fired when new data is received | item: The stream data item |
| stream-complete | Fired when the stream is complete | data: All stream data |
| stream-error | Fired when a stream error occurs | error: The error object |
| stream-finish | Fired when stream processing ends | - |
| stream-cancel | Fired when the stream is canceled | - |
# Precautions
- This mixin depends on the modern browser's Streams API. Please ensure your browser supports it before use.
- Errors that occur during stream processing are provided through the
streamErrorproperty and thestream-errorevent. - Relevant resources are automatically cleaned up when the component is destroyed.
- Custom transform streams need to implement
transformand optionalflushmethods. - For processing large amounts of data streams, it is recommended to implement throttling or batching to improve performance.