History is persisted in local storage

This commit is contained in:
Andrew Bastin
2019-08-22 17:13:09 +05:30
parent 1ab691108e
commit 07f5b57f4c

View File

@@ -26,7 +26,9 @@ const app = new Vue({
headers: '', headers: '',
body: '' body: ''
}, },
history: []
// Load history from local storage
history: window.localStorage.getItem("history") ? JSON.parse(window.localStorage.getItem("history")) : []
}, },
computed: { computed: {
rawRequestBody() { rawRequestBody() {
@@ -68,6 +70,9 @@ const app = new Vue({
methods: { methods: {
deleteHistory(entry) { deleteHistory(entry) {
this.history.splice(this.history.indexOf(entry), 1) this.history.splice(this.history.indexOf(entry), 1)
// Update the history
window.localStorage.setItem("history", JSON.stringify(this.history))
}, },
useHistory({ useHistory({
method, method,
@@ -93,6 +98,10 @@ const app = new Vue({
url: this.url, url: this.url,
path: this.path path: this.path
}) })
// Persist history in Local Storage
window.localStorage.setItem("history", JSON.stringify(this.history))
if (this.$refs.response.classList.contains('hidden')) { if (this.$refs.response.classList.contains('hidden')) {
this.$refs.response.classList.toggle('hidden') this.$refs.response.classList.toggle('hidden')
} }