cocos creator2.x 可以跟Vue结合,但是cocos creator 3.x不能跟Vue结合使用,请引擎大佬帮忙~!!!

因为cocos creator 3.0 build 后 生成的 application.js里面的

System.register([], function (_export, _context) {
"导致不能跟 Vue合并, 因为System.register是侵入式的,会抢夺Vue的主动权。

cocos creator 2.x 可以合并。
”window.boot = function () {
var settings = window._CCSettings;
window._CCSettings = undefined;
var onProgress = null;

1赞

楼主的问题解决了吗?我现在也遇到同样的问题

解决了。用iframe

1赞

用iframe可以将creator生成的东西嵌到网页,那怎么通讯呢

iframe父子之间传值

我是说creator怎么和vue通讯,比如我选择的是背包里面的刀,creator里面显示的就是刀

楼主解决cocoscreator 3.X跟Vue结合的了吗?

vue3使用了iframe嵌套cocos3.8发布项目,打开是灰屏,大佬是怎么解决的呢

现在行了吗,2024了

cocos端:
监听:window.addEventListener(‘message’, (e) => {
console.log(‘接收到事件’, e);

    })

发送:const imageData = this.canvas.toDataURL(“image/png”);
const event2 = { type: “newFrame”, detail: imageData }
if (window.parent) {
window.parent.postMessage(JSON.stringify(event2), “*”);
console.log(‘父页面’, window.parent);
}

vue端:
监听:window.addEventListener(“message”, (e: any) => {
try {
let data = JSON.parse(e.data);
console.log(‘接收到事件,vue2’, data);
} catch (e) {
console.log(e);
}
});
发送:const iframe = document.querySelector(‘iframe’);
console.log(iframe, iframe.contentWindow);
setInterval(() => {
iframe.contentWindow.postMessage(“从vue发来”, ‘*’);
}, 1000);

大佬我现在外面用uniapp写的

然后我里面是cocos

现在就是死活传不出来

你试试把监听的事件名称改成"message",只有这个事件名才能收到好像

你这个监听方法不是调用window.addEventListener吗,不管是监听还是发送都是基于window的事件系统,你再看看我发的。uniapp框架我没接触过,不过前端框架应该都差不多吧

uniapp里这样写只能在h5页面使用,一旦打包到app就运行不了了。