Comments (5)
from wujie.
好问题,在无界微前端中子应用代码运行在闭包内
为什么要在闭包内执行代码?
为了劫持修改 window.location,因为 location 的 configuable 为 false, 所以只能这样闭包解决
code = `(function(window, self, global, location) {
${code}
}).bind(window.__WUJIE.proxy)(
window.__WUJIE.proxy,
window.__WUJIE.proxy,
window.__WUJIE.proxy,
window.__WUJIE.proxyLocation,
);`;
想知道 window.location 修改了啥,可以看看 window.__WUJIE.proxyLocation
回到正题,为啥 var 不起作用呢,因为 var 在闭包内执行,怎么解决呢?看常见问题 2
有时我在想是不是出一个 api,让用户决定代码是否在 闭包内执行,毕竟这么干只是为了修改 location,用户可以直接从 window.$wujie.locaiton 拿到 修改后的 location 来用
from wujie.
好问题,在无界微前端中子应用代码运行在闭包内
为什么要在闭包内执行代码?
为了劫持修改 window.location,因为 location 的 configuable 为 false, 所以只能这样闭包解决
code = `(function(window, self, global, location) { ${code} }).bind(window.__WUJIE.proxy)( window.__WUJIE.proxy, window.__WUJIE.proxy, window.__WUJIE.proxy, window.__WUJIE.proxyLocation, );`;想知道 window.location 修改了啥,可以看看 window.__WUJIE.proxyLocation
回到正题,为啥 var 不起作用呢,因为 var 在闭包内执行,怎么解决呢?看常见问题 2
有时我在想是不是出一个 api,让用户决定代码是否在 闭包内执行,毕竟这么干只是为了修改 location,用户可以直接从 window.$wujie.locaiton 拿到 修改后的 location 来用
为什么不用一个闭包,要为每个script创建一个闭包
from wujie.
为什么不用一个闭包,要为每个script创建一个闭包
- 因为无界是边下载边执行的,fiber模式下,每个js文件都包裹在一个requestIdleCallback里面运行,如果要用一个闭包,那就需要先统一将所有js下载下来,然后再一个闭包内执行,效率太慢
- 异步js文件也还是没有办法塞到这个闭包内执行
另外,如果不想js代码在闭包内执行可以 使用 jsIgnores plugin 来实现了
from wujie.
@380815323 试下这个:#434 (comment)
from wujie.
Related Issues (20)
- 多层嵌套 HOT 1
- 主应用、子应用均为Vue2,子应用引入使用bpmn-js生成流程图,在火狐浏览器下,主应用嵌入子应用时不显示流程图。 HOT 3
- wujievue2 为什么不导出startApp HOT 1
- 子应用不能监听自定义合成事件 HOT 5
- 微前端对于write不支持 HOT 1
- 微信h5使用wujie后,在子应用展示二维码,ios长按二维码无响应,无法实现保存,分享,转发等操作,安卓正常 HOT 1
- 子应用引用第三方cdn静态js资源,加载出现跨域问题 HOT 1
- 无界 保活模式 一段时间不操作页面 #子应用出现边框且页面卡死,而且WujieVue.bus.$emit也无法触达子应用。 HOT 12
- 官网demo,子应用字体在重新激活时加载重复,生成两个一模一样的style标签
- 孙子应用的自定义@font-face不生效
- 子应用弹窗显示不了图片,position:fixed;或者absolute的时候不能展示图片。都是用的vue2,双向绑定也没问题就是渲染的时候img表情的src是空的
- window.$wujie.location.href 跳转问题 HOT 1
- 子应用中Popconfirm的确认事件无法被正确触发 HOT 2
- 这个仓库还在维护吗 HOT 6
- 子应用中使用 document.documentElement.addEventListener('keydown', ()=>{}) 绑定事件不生效
- wujie中无法正常是用worker
- 子应用中鼠标事件获取offset的值是基于wujie-app,不是基于指定元素
- vue3什么时候可以作为基座
- 子应用偶现白屏,且无报错
- 子应用打包部署后,antd组件库样式问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wujie.