1 Star 0 Fork 0

前端代码工具库 / vue-web-workers

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

vue-web-workers

A Vue component to use Web Workers in a simply way

Install

yarn add vue-web-workers
npm install vue-web-workers

Use

...
import VueWebWorkers from "vue-web-workers";

@Component({
  components: { VueWebWorkers }
})
export default DEMO extends Vue {
  private worker: Worker | null = null;
  private postMessage = { action: "", data: null };

  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  public onMessage(args: any) {
    console.log(args);
  }

  public sendByWorker() {
    this.worker && this.worker.postMessage({ action: "sendByWorker", data: null });
  }
  public sendByPostMessage() {
    this.postMessage = {
      action: "sendByPostMessage",
      data: null
    };
  }

  protected render() {
    return (
      <div >
        <VueWebWorkers v-model="worker" @message="onMessage" :postMessage="postMessage">
          addEventListener('message', async (event) => {
          setTimeout(() => postMessage(Object.assign({}, event.data, {state: true})), 1000)
          })
        </VueWebWorkers>
        <button @click="sendByWorker">SendByWorker</button>
        <button @click="sendByPostMessage">SendByPostMessage</button>
      </div>
    )
  }

}

Customize configuration

See GitHub.

Comments ( 0 )

Sign in for post a comment

About

A Vue component to use web worder in a simply way spread retract
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
TypeScript
1
https://git.oschina.net/tomxiang/vue-web-workers.git
git@git.oschina.net:tomxiang/vue-web-workers.git
tomxiang
vue-web-workers
vue-web-workers
master

Search