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 {
1010 append : ( ) => h ( 'span' , '.com' )
1111 } ;
1212 } ,
13+ widgetListeners : {
14+ input ( event ) {
15+ console . log ( 'ui input' , event ) ;
16+ }
17+ } ,
1318 renderChildren ( h ) {
1419 return [
1520 h ( 'span' , {
Original file line number Diff line number Diff line change @@ -254,6 +254,30 @@ uiSchema = {
254254> 1 . ` ui:widget ` 配置 ` HiddenWidget ` 或者 ` hidden ` 既可隐藏当前元素
255255> 1 . ` ui:hidden ` 支持配置表达式,详细参见这里 [ ui-schema ui: hidden 配置表达式] ( /zh/guide/data-linkage.html#ui-schema配置表达式 )
256256
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+
257281### ui-schema - slots
258282可以通过uiSchema配置render函数传递slot到你的Widget组件,使用方式如下:
259283
Original file line number Diff line number Diff line change @@ -221,6 +221,7 @@ export function getWidgetConfig({
221221 attrs : widgetAttrs ,
222222 class : widgetClass ,
223223 style : widgetStyle ,
224+ widgetListeners,
224225 fieldAttrs,
225226 fieldStyle,
226227 fieldClass,
@@ -250,6 +251,7 @@ export function getWidgetConfig({
250251 renderScopedSlots,
251252 renderChildren,
252253 onChange,
254+ widgetListeners,
253255 uiProps
254256 } ;
255257}
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ export default {
127127 type : Object ,
128128 default : ( ) => ( { } )
129129 } ,
130+ widgetListeners : null , // widget组件 emits
130131 formProps : null ,
131132 getWidget : null ,
132133 renderScopedSlots : null , // 作用域插槽
@@ -315,7 +316,13 @@ export default {
315316 scopedSlots : self . renderScopedSlots ( h ) || { }
316317 } : { } ) ,
317318 on : {
319+ ...self . widgetListeners ? self . widgetListeners : { } ,
318320 '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+
319326 // 提供一种特殊的配置 允许直接访问到 widget vm
320327 if ( self . getWidget && typeof self . getWidget === 'function' ) {
321328 self . getWidget . call ( null , self . $refs . widgetRef ) ;
@@ -339,6 +346,11 @@ export default {
339346 } ) ;
340347 }
341348 }
349+
350+ if ( self . widgetListeners && self . widgetListeners . input ) {
351+ // eslint-disable-next-line prefer-rest-params
352+ self . widgetListeners . input . apply ( this , [ ...arguments ] ) ;
353+ }
342354 }
343355 }
344356 } ,
You can’t perform that action at this time.
0 commit comments