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

fix(v3): decode query (onLoad)

上级 2c8d9d3a
import {
decodedQuery
} from 'uni-shared'
import {
callPageHook
} from '../util'
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 () {
return {
created: function pageCreated () {
const options = getDecodedQuery(this.$route.query)
const options = decodedQuery(this.$route.query)
createPage(this, options)
callPageHook(this, 'onLoad', options)
callPageHook(this, 'onShow')
......
import {
hasOwn
hasOwn,
decodedQuery
} from 'uni-shared'
import {
......@@ -86,7 +87,8 @@ export function initLifecycle (Vue) {
},
created () {
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')
}
},
......
......@@ -69,4 +69,16 @@ export function stringifyQuery (obj, encodeStr = encode) {
return encodeStr(key) + '=' + encodeStr(val)
}).filter(x => x.length > 0).join('&') : null
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.
先完成此消息的编辑!
想要评论请 注册