File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -72,10 +72,33 @@ let app = new Vue({
7272 cm . showHint ( e ) ;
7373 }
7474 } ) ;
75- this . editor . on ( "change" , ( cm , change ) => {
75+ this . editor . on ( "change" , ( cm , e ) => {
7676 this . refresh ( ) ;
7777 this . saveEditorContent ( this . editor , '__editor_content' ) ;
7878 } ) ;
79+
80+ // 粘贴上传图片并插入
81+ this . editor . on ( "paste" , ( cm , e ) => {
82+ if ( ! ( e . clipboardData && e . clipboardData . items ) ) {
83+ return ;
84+ }
85+ for ( let i = 0 , len = e . clipboardData . items . length ; i < len ; ++ i ) {
86+ let item = e . clipboardData . items [ i ] ;
87+ if ( item . kind === 'file' ) {
88+ const pasteFile = item . getAsFile ( ) ;
89+ let data = new FormData ( ) ;
90+ data . append ( "file" , pasteFile ) ;
91+ axios . post ( 'https://imgkr.com/api/files/upload' , data , {
92+ headers : {
93+ 'Content-Type' : 'multipart/form-data'
94+ }
95+ } ) . then ( resp => {
96+ this . uploaded ( resp . data )
97+ } ) . catch ( err => {
98+ } )
99+ }
100+ }
101+ } ) ;
79102 this . cssEditor . on ( 'update' , ( instance ) => {
80103 this . cssChanged ( ) ;
81104 this . saveEditorContent ( this . cssEditor , '__css_content' ) ;
You can’t perform that action at this time.
0 commit comments