- 注意,该 api 需要配合 enablePolyfills(['1.0'])
使用
+ 注意,该 api 需要配合 enablePolyfills(['1.0'])
使用
### registerTypeDefaultComponents
diff --git a/packages/vue/docs/demos/api/shared/observer.vue b/packages/vue/docs/demos/api/shared/observer.vue
index 9556662b2a4..62b95623548 100644
--- a/packages/vue/docs/demos/api/shared/observer.vue
+++ b/packages/vue/docs/demos/api/shared/observer.vue
@@ -15,34 +15,37 @@
diff --git a/packages/vue/package.json b/packages/vue/package.json
index 07ef1d9e7d4..0ab0a935e53 100644
--- a/packages/vue/package.json
+++ b/packages/vue/package.json
@@ -42,6 +42,7 @@
"@formily/shared": "2.0.0-beta.72",
"@formily/validator": "2.0.0-beta.72",
"@type-helper/vue3": "npm:vue@3",
+ "@type-helper/vue2": "npm:vue@2",
"vue-demi": "^0.9.0",
"vue-frag": "^1.1.4"
},
diff --git a/packages/vue/src/__tests__/field.spec.ts b/packages/vue/src/__tests__/field.spec.ts
index 7d360037318..58caa0d9b29 100644
--- a/packages/vue/src/__tests__/field.spec.ts
+++ b/packages/vue/src/__tests__/field.spec.ts
@@ -2,18 +2,14 @@ import Vue, { FunctionalComponentOptions } from 'vue'
import { render, fireEvent, waitFor } from '@testing-library/vue'
import { defineComponent, h } from '@vue/composition-api'
import { createForm } from '@formily/core'
+import { useField, useFormEffects, connect, mapProps, mapReadPretty } from '../'
import {
FormProvider,
ArrayField,
ObjectField,
VoidField,
Field,
- useField,
- useFormEffects,
- connect,
- mapProps,
- mapReadPretty,
-} from '../'
+} from '../vue2-components'
import ReactiveField from '../components/ReactiveField'
// import { expectThrowError } from './shared'
import { isField, isVoidField, onFieldChange } from '@formily/core'
@@ -23,7 +19,7 @@ Vue.component('ArrayField', ArrayField)
Vue.component('ObjectField', ObjectField)
Vue.component('VoidField', VoidField)
Vue.component('Field', Field)
-Vue.component('ReactiveField', ReactiveField)
+Vue.component('ReactiveField', ReactiveField as unknown as Vue)
const Decorator: FunctionalComponentOptions = {
functional: true,
diff --git a/packages/vue/src/__tests__/form.spec.ts b/packages/vue/src/__tests__/form.spec.ts
index a3c9d505172..c4d76ba46e0 100644
--- a/packages/vue/src/__tests__/form.spec.ts
+++ b/packages/vue/src/__tests__/form.spec.ts
@@ -1,8 +1,7 @@
import Vue from 'vue'
import { render } from '@testing-library/vue'
import { createForm } from '@formily/core'
-import { FormProvider } from '../'
-import { FormConsumer } from '../components'
+import { FormProvider, FormConsumer } from '../vue2-components'
Vue.component('FormProvider', FormProvider)
Vue.component('FormConsumer', FormConsumer)
diff --git a/packages/vue/src/__tests__/schema.json.spec.ts b/packages/vue/src/__tests__/schema.json.spec.ts
index 32f64eb512a..d76cf0bba6d 100644
--- a/packages/vue/src/__tests__/schema.json.spec.ts
+++ b/packages/vue/src/__tests__/schema.json.spec.ts
@@ -1,8 +1,8 @@
import { createForm } from '@formily/core'
-import { FormProvider, createSchemaField } from '../index'
import { Schema } from '@formily/json-schema'
import { render } from '@testing-library/vue'
import Vue, { FunctionalComponentOptions } from 'vue'
+import { FormProvider, createSchemaField } from '../vue2-components'
Vue.component('FormProvider', FormProvider)
@@ -21,6 +21,36 @@ const Input: FunctionalComponentOptions = {
},
}
+const Previewer: FunctionalComponentOptions = {
+ functional: true,
+ render(h, context) {
+ return h(
+ 'div',
+ {
+ attrs: {
+ 'data-testid': 'previewer',
+ },
+ },
+ context.children
+ )
+ },
+}
+
+const Previewer2: FunctionalComponentOptions = {
+ functional: true,
+ render(h, context) {
+ return h(
+ 'div',
+ {
+ attrs: {
+ 'data-testid': 'previewer2',
+ },
+ },
+ [context.scopedSlots.content({})]
+ )
+ },
+}
+
describe('json schema field', () => {
test('string field', () => {
const form = createForm()
@@ -85,3 +115,184 @@ describe('json schema field', () => {
expect(queryByTestId('input')).toBeVisible()
})
})
+
+describe('x-content', () => {
+ test('default slot', () => {
+ const form = createForm()
+ const { SchemaField } = createSchemaField({
+ components: {
+ Previewer,
+ },
+ })
+ const { queryByTestId } = render({
+ components: { SchemaField },
+ data() {
+ return {
+ form,
+ schema: new Schema({
+ type: 'string',
+ 'x-component': 'Previewer',
+ 'x-content': '123',
+ }),
+ }
+ },
+ template: `