mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 10:08:52 +08:00
refactor reading predefined queries
This commit is contained in:
@@ -113,5 +113,12 @@ export default {
|
||||
document.body.append(uploader)
|
||||
}
|
||||
uploader.click()
|
||||
},
|
||||
|
||||
readPredefinedQueries () {
|
||||
return fetch('./queries.json')
|
||||
.then(resp => {
|
||||
return resp.json()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,35 +13,7 @@ import '@/assets/styles/scrollbars.css'
|
||||
|
||||
export default {
|
||||
name: 'MainView',
|
||||
components: { MainMenu },
|
||||
created () {
|
||||
this.readPredefinedQueries()
|
||||
.then(queries => {
|
||||
this.$store.commit('updatePredefinedQueries', queries)
|
||||
})
|
||||
.catch(console.error)
|
||||
},
|
||||
methods: {
|
||||
readPredefinedQueries () {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest()
|
||||
xhr.open('GET', './queries.json')
|
||||
xhr.onload = () => {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
resolve(JSON.parse(xhr.responseText || '[]'))
|
||||
} else {
|
||||
reject(xhr.statusText)
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.onerror = () => {
|
||||
reject(xhr.statusText)
|
||||
}
|
||||
xhr.send()
|
||||
})
|
||||
}
|
||||
}
|
||||
components: { MainMenu }
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
|
||||
@@ -214,7 +214,14 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.queries = storedQueries.getStoredQueries()
|
||||
storedQueries.readPredefinedQueries()
|
||||
.then(queries => {
|
||||
this.$store.commit('updatePredefinedQueries', queries)
|
||||
})
|
||||
.catch(console.error)
|
||||
.finally(() => {
|
||||
this.queries = storedQueries.getStoredQueries()
|
||||
})
|
||||
},
|
||||
mounted () {
|
||||
this.resizeObserver = new ResizeObserver(this.calcMaxTableHeight)
|
||||
|
||||
Reference in New Issue
Block a user