提交 9fee8265 编写于 作者: fxy060608's avatar fxy060608

fix: onLoad 接收参数增加一次 decode 操作,与小程序保持相同逻辑

上级 ca51beb6
import getRealRoute from '../get-real-route'
function encodeQueryString (url) {
if (typeof url === 'string') {
const urls = url.split('?')
url = urls[0]
const params = [];
(urls[1] || '').split('&').forEach(function (pair) {
if (pair) {
const pairs = pair.split('=')
params.push(pairs[0] + '=' + encodeURIComponent(pairs[1]))
}
})
return params.length ? url + '?' + params.join('&') : url
}
return url
}
function createValidator (type) {
return function validator (url, params) {
// 格式化为绝对路径路由
......@@ -36,6 +55,9 @@ function createValidator (type) {
if (routeOptions.meta.isEntry) {
url = url.replace(routeOptions.alias, '/')
}
// 参数格式化
params.url = encodeQueryString(url)
}
}
......
......@@ -3,11 +3,25 @@ import {
} 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 () {
createPage(this)
callPageHook(this, 'onLoad', this.$route.query)
callPageHook(this, 'onLoad', getDecodedQuery(this.$route.query))
callPageHook(this, 'onShow')
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册