1
0
Fork 0
mirror of https://github.com/Luzifer/wiki.git synced 2024-12-21 11:01:19 +00:00
wiki/src/edit.vue

90 lines
1.6 KiB
Vue
Raw Normal View History

2019-08-04 22:42:37 +00:00
<template>
<b-container>
<b-row>
<b-col>
<textarea ref="editor" />
<b-btn
variant="primary"
@click="save"
>
Save
</b-btn>
</b-col>
</b-row>
</b-container>
</template>
<script>
import axios from 'axios'
import EasyMDE from 'easymde'
export default {
name: 'Edit',
data() {
return {
editor: null,
}
},
watch: {
'$route'(to, from) {
if (to.params.page === from.params.page) {
return
}
this.loadPage(to.params.page)
},
},
mounted() {
if (!this.editor) {
this.editor = new EasyMDE({
element: this.$refs.editor,
forceSync: true,
indentWithTabs: false,
})
window.editor = this.editor
}
this.loadPage(this.$route.params.page)
},
methods: {
loadPage(pageName) {
console.debug(`Loading ${pageName}...`)
axios.get(`/_content/${pageName}`)
.then(resp => {
this.editor.codemirror.setValue(resp.data.content)
})
.catch(err => {
if (err.response && err.response.status === 404) {
return
}
console.error(err)
// FIXME: Show error
})
},
save() {
axios.post(`/_content/${this.$route.params.page}`, {
content: this.$refs.editor.value,
})
.then(() => {
this.$router.push({ name: 'view', params: { page: this.$route.params.page } })
})
.catch(err => {
console.error(err)
})
},
},
}
</script>
<style>
.editor-toolbar {
background-color: #ccc;
}
</style>