import editorJS from '@editorjs/editorjs';
import editorHeader from '@editorjs/header';
export default ( context, inject ) => {
const defaultOptions = {
id: '',
data: {},
onChange: () => {},
}
const editor = ( options = defaultOptions ) => {
return new editorJS( {
placeholder: 'Писать тут !',
holder: options.id,
tools: {
header: editorHeader,
},
data: options.data || {},
onChange( data ) {
// pass in function from component to run on change
options.onChange( data )
}
} )
};
inject( 'editor', options => editor( options ) );
}
...
<editorjs :content="post.data" />
...
async mount() {
await this.$store.dispatch( 'posts/editPost' )
this.post = this.$store.state.posts.post
}
...
...
<div id="editorjs" class="editorjs" />
...
mounted() {
const editorOptions = {
id: 'editorjs',
data: this.content || {},
onChange: this.onChange
};
this.editor = this.$editor( editorOptions );
}
<template>
<div>
<div id="editorjs" class="editorjs" />
{{ editorData }}
</div>
</template>
...
computed: {
editorData() {
if ( Object.assign( {}, this.content ) ) {
if ( !this.dataLoaded && this.content ) {
const editorOptions = {
id: 'editorjs',
data: Object.assign( {}, this.content ) || {},
onChange: this.onChange
};
this.editor = this.$editor( editorOptions );
this.dataLoaded = true // семафор получения данных
}
}
return null
}
},
...
if ( 1 === 1 ) {
echo 'Правильно' }
if (!1 === 2 ) {
echo 'Правильно' }
Несколько способов клонировать массивы.