no message
Former-commit-id: 15ad9c05579d01041b7249cd81eda4bbb4b2f85b Former-commit-id: 25b3a6afc1d967fd474038767af4a347498a0d88 Former-commit-id: e368a69ee8117e3439542ae011181270b9c8dd71
This commit is contained in:
61
src/components/core/d2-mde/index.vue
Normal file
61
src/components/core/d2-mde/index.vue
Normal file
@@ -0,0 +1,61 @@
|
||||
<template>
|
||||
<textarea ref="mde"></textarea>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import SimpleMDE from 'simplemde'
|
||||
export default {
|
||||
name: 'd2-mde',
|
||||
props: {
|
||||
// 值
|
||||
value: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: ''
|
||||
},
|
||||
// 配置参数
|
||||
config: {
|
||||
type: Object,
|
||||
required: false,
|
||||
default: () => ({})
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
// 编辑器实例
|
||||
mde: null,
|
||||
// 编辑器默认参数
|
||||
// 详见 https://github.com/sparksuite/simplemde-markdown-editor#configuration
|
||||
defaultConfig: {
|
||||
autoDownloadFontAwesome: false
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
// 初始化
|
||||
this.init()
|
||||
},
|
||||
destroyed () {
|
||||
// 在组件销毁后销毁实例
|
||||
this.mde = null
|
||||
},
|
||||
methods: {
|
||||
// 初始化
|
||||
init () {
|
||||
// 合并参数
|
||||
const config = Object.assign({}, this.defaultConfig, this.config)
|
||||
// 初始化
|
||||
this.mde = new SimpleMDE({
|
||||
...config,
|
||||
// 初始值
|
||||
initialValue: this.value,
|
||||
// 挂载元素
|
||||
element: this.$refs.mde
|
||||
})
|
||||
this.mde.codemirror.on('change', () => {
|
||||
this.$emit('input', this.mde.value())
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user