Skip to content

Commit

Permalink
chore: fix demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Sep 25, 2023
1 parent dcabb84 commit 19501c6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/.vitepress/theme/components/playground-block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,9 @@ export default {
name: "PlaygroundBlock",
components: { PgEditor, RulesSettings, SnsBar },
data() {
const serializedString =
(typeof window !== "undefined" && window.location.hash.slice(1)) || "";
const state = deserializeState(serializedString);
return {
code: state.code || DEFAULT_CODE,
rules: state.rules || Object.assign({}, DEFAULT_RULES_CONFIG),
code: DEFAULT_CODE,
rules: Object.assign({}, DEFAULT_RULES_CONFIG),
messages: [],
};
},
Expand All @@ -75,12 +72,16 @@ export default {
},
watch: {
serializedString(serializedString) {
if (typeof window !== "undefined") {
if (
typeof window !== "undefined" &&
serializedString !== window.location.hash.slice(1)
) {
window.location.replace(`#${serializedString}`);
}
},
},
mounted() {
this.onUrlHashChange();
if (typeof window !== "undefined") {
window.addEventListener("hashchange", this.onUrlHashChange);
}
Expand All @@ -104,7 +105,6 @@ export default {
const state = deserializeState(serializedString);
this.code = state.code || DEFAULT_CODE;
this.rules = state.rules || Object.assign({}, DEFAULT_RULES_CONFIG);
this.script = state.script;
}
},
},
Expand Down

0 comments on commit 19501c6

Please sign in to comment.