提交 5d1c7dc4 编写于 作者: fxy060608's avatar fxy060608

fix(v3): decode query (onLoad)

上级 2c8d9d3a
import {
decodedQuery
} from 'uni-shared'
import { import {
callPageHook callPageHook
} from '../util' } from '../util'
import createPage from './create-page' import createPage from './create-page'
// 与小程序保持一致,尝试decodeURIComponent一次参数
function getDecodedQuery (query = {}) {
const decodedQuery = {}
Object.keys(query).forEach(name => {
try {
decodedQuery[name] = decodeURIComponent(query[name])
} catch (e) {
decodedQuery[name] = query[name]
}
})
return decodedQuery
}
export function createPageMixin () { export function createPageMixin () {
return { return {
created: function pageCreated () { created: function pageCreated () {
const options = getDecodedQuery(this.$route.query) const options = decodedQuery(this.$route.query)
createPage(this, options) createPage(this, options)
callPageHook(this, 'onLoad', options) callPageHook(this, 'onLoad', options)
callPageHook(this, 'onShow') callPageHook(this, 'onShow')
......
import { import {
hasOwn hasOwn,
decodedQuery
} from 'uni-shared' } from 'uni-shared'
import { import {
...@@ -86,7 +87,8 @@ export function initLifecycle (Vue) { ...@@ -86,7 +87,8 @@ export function initLifecycle (Vue) {
}, },
created () { created () {
if (this.mpType === 'page') { if (this.mpType === 'page') {
callPageHook(this.$scope, 'onLoad', this.$options.pageQuery) // 理论上应该从最开始的 parseQuery 的地方直接 decode 两次,为了减少影响范围,先仅处理 onLoad 参数
callPageHook(this.$scope, 'onLoad', decodedQuery(this.$options.pageQuery))
callPageHook(this.$scope, 'onShow') callPageHook(this.$scope, 'onShow')
} }
}, },
......
...@@ -70,3 +70,15 @@ export function stringifyQuery (obj, encodeStr = encode) { ...@@ -70,3 +70,15 @@ export function stringifyQuery (obj, encodeStr = encode) {
}).filter(x => x.length > 0).join('&') : null }).filter(x => x.length > 0).join('&') : null
return res ? `?${res}` : '' return res ? `?${res}` : ''
} }
export function decodedQuery (query = {}) {
const decodedQuery = {}
Object.keys(query).forEach(name => {
try {
decodedQuery[name] = decode(query[name])
} catch (e) {
decodedQuery[name] = query[name]
}
})
return decodedQuery
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册