Movatterモバイル変換


[0]ホーム

URL:


useWeb

# Web Worker

This functions provides simple web worker registration and communication.

# State

TheuseWorker function exposes the following reactive state:

import{ useWorker}from'vue-use-web';const{ data}=useWorker('/path/to/worker.js');
StateTypeDescription
dataRef<any>Reference to the latest data received via the worker, can be watched to respond to incoming messages

# Methods

useWorker exposes the following methods:

import{ useWorker}from'vue-use-web';const{ post, terminate}=useWorker('/path/to/worker.js');
MethodSignatureDescription
post(data: any) => voidSends data to the worker thread.
terminate() => voidStops and terminates the worker.

# Example

<template><div><inputtype="text"v-model="message"/><button@click="post(message)">Send</button><button@click="close()">Close</button>    State: {{ state }}    Worker messages:<pre>{{ messages }}</pre></div></template><script>import{ ref, watch}from'@vue/composition-api';import{ useWorker}from'vue-use-web';exportdefault{setup(){const{ data, post}=useWorker('/path/to/worker.js');const message=ref('');const messages=ref([]);watch(      data,val=>{        messages.value.push(val);},{ lazy:true});return{ post, message, messages};}};</script>

[8]ページ先頭

©2009-2025 Movatter.jp