Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue项目报错:Uncaught SyntaxError: Unexpected token < #1661

Closed
wangzhiyao66 opened this issue Jan 6, 2020 · 1 comment
Closed

Vue项目报错:Uncaught SyntaxError: Unexpected token < #1661

wangzhiyao66 opened this issue Jan 6, 2020 · 1 comment

Comments

@wangzhiyao66
Copy link

@wangzhiyao66 wangzhiyao66 commented Jan 6, 2020

  1. Vue and Typescript Projects built
    2.I want to use webworker to count user data,
  2. The code snippet is as follows
    // webworker.js
    `
    onmessage = function (event) {
    // postmessage的参数
    const eventData = {
    token: event.data.token,
    requestData: event.data,
    url: event.data.url,
    }

// 请求地址 在 worker.service.ts 里面

const sleep = function (time) {
/**
*
* @param {} data 请求参数
* @param {
} callback 请求成功回掉函数
*/
var xhr = function (data, callback) {
// console.log('worker 参数', data);
const workerdata = JSON.parse(JSON.stringify(data));
if (workerdata) {
delete workerdata.token;
delete workerdata.url;
}
// fetch 请求方式
fetch(eventData.url, {
body: JSON.stringify(workerdata), // must match 'Content-Type' header
headers: {
"Authorization": "Bearer " + eventData.token,
"Content-Type": "application/json;charset=UTF-8"
},
method: 'POST', // *GET, POST, PUT, DELETE, etc.
})
.then(res => {
if (res.ok) {
return res.json();
}
throw new Error('Network response was not ok.');
})
.then(function (data) {
// console.log(JSON.stringify(data));
// console.table(data);
console.log('%c webworker请求成功 fetch方式 开始收集数据', 'color:orange');
callback();
}, function (err) {
console.error(err);
})
.catch(error => console.error('Error:', error))
}

return new Promise(function (resolve, reject) {
  const obj = {
    data: 'ok',
    type: 'worker'
  };

  xhr(eventData.requestData, function () {
    resolve(obj);
  });
});

};

// 立即执行的 async 函数
(async () => {
const result = await sleep(event.data);
postMessage(result);
// console.log('在使用importScripts()的文件中调用:' + kk());
close();
})();
};
`
// An error occurred during a method call

`
if (typeof Worker !== 'undefined') {
this.worker = new Worker('../../../../../static/js/webworker.js'); // 需要每次都调用打开一个woker
console.log( 'msg =========', msg);

        // 可以序列化为JSON结构的任何值都可以作为参数传递给 postMessage();
        this.worker.postMessage(msg);
        this.worker.onmessage = (event: any) => {
          this.worker_data = event.data;
        };
        console.log('start Web Workers...');
      } else {
        console.log('Sorry, your browser does not support Web Workers...');
      }

`

I need your help to solve this problem. Thank you very much

@vue-bot

This comment has been minimized.

Copy link

@vue-bot vue-bot commented Jan 6, 2020

Hello, thank you for taking time filling this issue!

However, we kindly ask you to use our Issue Helper when creating new issues, in order to ensure every issue provides the necessary information for us to investigate. This explains why your issue has been automatically closed by me (your robot friend!).

I hope to see your helper-created issue very soon!


你好,你的 issue 不符合我们所要求的格式,因此已被自动关闭。为了确保每个 issue 都提供必需的相关信息,请务必使用我们的 Issue 向导 来创建新 issue,谢谢!

@vue-bot vue-bot closed this Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.