2021-04-11 02:55:26 +02:00
|
|
|
import queryString from 'query-string';
|
2021-08-22 04:28:11 +02:00
|
|
|
import merge from 'merge';
|
2021-04-11 02:55:26 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
methods: {
|
|
|
|
qs(merge) {
|
|
|
|
var c = queryString.parse(window.location.search);
|
|
|
|
|
|
|
|
var m = { ...c, ...merge };
|
|
|
|
var mn = {};
|
|
|
|
|
|
|
|
Object.keys(m).forEach((k) => {
|
2021-04-11 10:17:30 +02:00
|
|
|
if (m[k] !== null) {
|
2021-04-11 02:55:26 +02:00
|
|
|
mn[k] = m[k];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var merged = queryString.stringify(mn);
|
|
|
|
|
|
|
|
return window.location.pathname + (merged ? '?'+merged : '');
|
2021-08-22 04:28:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
query(options) {
|
|
|
|
options = merge({
|
|
|
|
only: null,
|
|
|
|
}, options);
|
|
|
|
var c = queryString.parse(window.location.search);
|
|
|
|
|
|
|
|
if (options.only !== null) {
|
|
|
|
for (var k in c) {
|
|
|
|
if (options.only.indexOf(k) < 0) {
|
|
|
|
delete c[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.keys(c).length === 0 ? '' : `?${queryString.stringify(c)}`;
|
2021-04-11 02:55:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|