From 07f5b57f4c01b12a9245661da76245323fc0a979 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Thu, 22 Aug 2019 17:13:09 +0530 Subject: [PATCH] History is persisted in local storage --- script.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index d55b431bf..3a853bd6f 100644 --- a/script.js +++ b/script.js @@ -26,7 +26,9 @@ const app = new Vue({ headers: '', body: '' }, - history: [] + + // Load history from local storage + history: window.localStorage.getItem("history") ? JSON.parse(window.localStorage.getItem("history")) : [] }, computed: { rawRequestBody() { @@ -68,6 +70,9 @@ const app = new Vue({ methods: { deleteHistory(entry) { this.history.splice(this.history.indexOf(entry), 1) + + // Update the history + window.localStorage.setItem("history", JSON.stringify(this.history)) }, useHistory({ method, @@ -93,6 +98,10 @@ const app = new Vue({ url: this.url, path: this.path }) + + // Persist history in Local Storage + window.localStorage.setItem("history", JSON.stringify(this.history)) + if (this.$refs.response.classList.contains('hidden')) { this.$refs.response.classList.toggle('hidden') }