-
Notifications
You must be signed in to change notification settings - Fork 370
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
修改在刷新webview页面后message未被销毁的问题 #1500
Conversation
@@ -138,7 +138,16 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t | |||
...webRouteConfig, | |||
routes: routes | |||
}) | |||
global.__mpxRouter.stack = [] | |||
const sessionStorage = window.sessionStorage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
添加ssr判断
@@ -252,6 +261,14 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t | |||
global.__mpxRouter.needCache = insertItem | |||
} | |||
} | |||
if (sessionStorage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ssr
@@ -113,8 +113,9 @@ | |||
}, window.sdkUrlMap); | |||
var env = null; | |||
var callbackId = 0; | |||
var clientUid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通过query传递获取吧
@@ -55,6 +55,9 @@ | |||
if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) { | |||
this.mpxIframe = this.$refs.mpxIframe | |||
this.mpxIframe.addEventListener('load', (event) => { | |||
this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成url query传递
mpxStackPath = [] | ||
} | ||
} | ||
global.__mpxRouter.stack = mpxStackPath || [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要||[]
mpxStackPath = JSON.parse(sessionStorage.getItem('_mpx_stack_path_')) | ||
} | ||
} catch (e) { | ||
mpxStackPath = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要
const srcQueryIndex = this.src.indexOf('?') | ||
// webview与被打开页面通过_uid确定关联关系 | ||
if (srcQueryIndex > -1) { | ||
src = `${this.src.substring(0, srcQueryIndex + 1)}_mpx_webview_id=${this._uid}&${this.src.substring(srcQueryIndex + 1)}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉都有mpx前缀了就不用_开头了
@@ -62,11 +62,25 @@ const SDK_URL_MAP = { | |||
}, | |||
...window.sdkUrlMap | |||
}; | |||
|
|||
function getQueryObj () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成正则匹配获取id把
let env = null; | ||
let callbackId = 0; | ||
let clientUid = +getQueryObj()._mpx_webview_id || undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|| undefined 不需要
packages/webview-bridge/src/index.js
Outdated
@@ -108,6 +122,7 @@ function postMessage (type, data = {}) { | |||
window.parent.postMessage && window.parent.postMessage({ | |||
type, | |||
callbackId, | |||
clientUid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
判断一下没有clientUid的情况这里也不用发送了
packages/webview-bridge/src/index.js
Outdated
let env = null | ||
let callbackId = 0 | ||
let clientUid = +getQueryObj()._mpx_webview_id || undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该不需要精确类型以及添加||undefined,可以在接受的时候处理
@@ -52,17 +67,6 @@ | |||
width: sizeStr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch有意义么
packages/webview-bridge/src/index.js
Outdated
|
||
function getMpxWebViewId () { | ||
const href = location.href | ||
const reg = /(?<=mpx_webview_id=)\d*/g |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个正则匹配有点非主流。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/mpx_webview_id=(\d+)/ match[1]
packages/webview-bridge/src/index.js
Outdated
type, | ||
callbackId, | ||
payload: filterData(data) | ||
}, '*') | ||
} | ||
if (typeof clientUid !== 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dist没重新构建,以及比较undefined不需要typeof,直接判断clientUid!==undefined就行了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上面也有类似的判断,一起改一下
7f0ecff
to
756eba0
Compare
No description provided.