A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://Tarektouati.github.io/vue-use-web/functions/worker.html below:

Website Navigation


Web Worker | useWeb

# Web Worker

This functions provides simple web worker registration and communication.

# State

The useWorker function exposes the following reactive state:

import { useWorker } from 'vue-use-web';

const { data } = useWorker('/path/to/worker.js');
State Type Description data Ref<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');
Method Signature Description post (data: any) => void Sends data to the worker thread. terminate () => void Stops and terminates the worker. # Example
<template>
  <div>
    <input type="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';

export default {
  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>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4