mirror of
https://github.com/Luzifer/wiki.git
synced 2024-12-21 11:01:19 +00:00
90 lines
1.6 KiB
Vue
90 lines
1.6 KiB
Vue
|
<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>
|