File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed
demo/demo-v2/src/pages/vue-editor/views/editor/viewComponents/Text
vue2/vue2-core/src/components Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ export default {
10
10
append : ( ) => h ( 'span' , '.com' )
11
11
} ;
12
12
} ,
13
+ widgetListeners : {
14
+ input ( event ) {
15
+ console . log ( 'ui input' , event ) ;
16
+ }
17
+ } ,
13
18
renderChildren ( h ) {
14
19
return [
15
20
h ( 'span' , {
Original file line number Diff line number Diff line change @@ -254,6 +254,30 @@ uiSchema = {
254
254
> 1 . ` ui:widget ` 配置 ` HiddenWidget ` 或者 ` hidden ` 既可隐藏当前元素
255
255
> 1 . ` ui:hidden ` 支持配置表达式,详细参见这里 [ ui-schema ui: hidden 配置表达式] ( /zh/guide/data-linkage.html#ui-schema配置表达式 )
256
256
257
+ ### ui-schema - events
258
+ 可以通过uiSchema widgetListeners 配置组件 emit events
259
+
260
+ ::: warning
261
+ * 注意该配置只适合 ` vue2 `
262
+ * ` vue3 ` 的版本可以直接传递 ` ui:onXxx ` 即可,参见:[ vue3 listeners] ( https://v3.cn.vuejs.org/guide/migration/listeners-removed.html#%E6%A6%82%E8%A7%88 )
263
+ :::
264
+
265
+ > 如下:通过配置 ui widgetListener配置widget组件内的events
266
+
267
+ ``` js
268
+ {
269
+ ' ui:options' : {
270
+ widgetListeners: {
271
+ input (event ) {
272
+ console .log (' ui input' , event );
273
+ }
274
+ }
275
+ }
276
+ }
277
+ ```
278
+
279
+
280
+
257
281
### ui-schema - slots
258
282
可以通过uiSchema配置render函数传递slot到你的Widget组件,使用方式如下:
259
283
Original file line number Diff line number Diff line change @@ -221,6 +221,7 @@ export function getWidgetConfig({
221
221
attrs : widgetAttrs ,
222
222
class : widgetClass ,
223
223
style : widgetStyle ,
224
+ widgetListeners,
224
225
fieldAttrs,
225
226
fieldStyle,
226
227
fieldClass,
@@ -250,6 +251,7 @@ export function getWidgetConfig({
250
251
renderScopedSlots,
251
252
renderChildren,
252
253
onChange,
254
+ widgetListeners,
253
255
uiProps
254
256
} ;
255
257
}
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ export default {
127
127
type : Object ,
128
128
default : ( ) => ( { } )
129
129
} ,
130
+ widgetListeners : null , // widget组件 emits
130
131
formProps : null ,
131
132
getWidget : null ,
132
133
renderScopedSlots : null , // 作用域插槽
@@ -315,7 +316,13 @@ export default {
315
316
scopedSlots : self . renderScopedSlots ( h ) || { }
316
317
} : { } ) ,
317
318
on : {
319
+ ...self . widgetListeners ? self . widgetListeners : { } ,
318
320
'hook:mounted' : function widgetMounted ( ) {
321
+ if ( self . widgetListeners && self . widgetListeners [ 'hook:mounted' ] ) {
322
+ // eslint-disable-next-line prefer-rest-params
323
+ self . widgetListeners [ 'hook:mounted' ] . apply ( this , [ ...arguments ] ) ;
324
+ }
325
+
319
326
// 提供一种特殊的配置 允许直接访问到 widget vm
320
327
if ( self . getWidget && typeof self . getWidget === 'function' ) {
321
328
self . getWidget . call ( null , self . $refs . widgetRef ) ;
@@ -339,6 +346,11 @@ export default {
339
346
} ) ;
340
347
}
341
348
}
349
+
350
+ if ( self . widgetListeners && self . widgetListeners . input ) {
351
+ // eslint-disable-next-line prefer-rest-params
352
+ self . widgetListeners . input . apply ( this , [ ...arguments ] ) ;
353
+ }
342
354
}
343
355
}
344
356
} ,
You can’t perform that action at this time.
0 commit comments