单纯html,启本地服务可以。vue3里引入3个js文件,运行报错说没System。有没有可以直接运行的项目例子
你要把打包的内容链接在另外一个页面打开么
不用链接,vue3项目里直接引入那几个js文件,调用初始化的那些函数显示
没太明白…
3.x不支持file协议
在vue组件里用iframe嵌入项目,但目前还没搞明白两个项目怎么通讯,楼主有好的办法吗
cocos发送我用的是 缓存 iframe发送到cocos用的这个 window.parent.postMessage(JSON.stringify(obj), “*”); obj 是发动的对象, cocos接收是这个 window.addEventListener(“message”, function (result) { });
感谢感谢,我刚接触前端,所以cocos这边是无法访问到父窗口,只能使用缓存是吗。你这里的iframe指的是创建了iframe的那个组件吗
应该是可以的,不过我没试,因为用缓存可以完成需求, 对 iframe 那个组件里的页面可以用postMessage发送
好的,再次感谢
两个项目通讯:
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);