Skip to content

Commit fe43fbb

Browse files
author
LKCCY
committed
fix: schema-form插槽错误
1 parent 8852ce5 commit fe43fbb

File tree

9 files changed

+148
-7
lines changed

9 files changed

+148
-7
lines changed

docs/.vuepress/components/code-contain.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import AddItem from './add-item'
2222
import LayoutGutter from './layout-gutter'
2323
import LayoutOffset from './layout-offset'
2424
import LayoutFlexible from './layout-flexible'
25-
25+
// slot 布局
26+
import SlotFront from './slot-front'
27+
import SlotRear from './slot-rear'
28+
import SlotSlot from './slot-slot'
2629
2730
export default {
2831
props: {
@@ -38,7 +41,10 @@ export default {
3841
AddItem,
3942
LayoutGutter,
4043
LayoutOffset,
41-
LayoutFlexible
44+
LayoutFlexible,
45+
SlotFront,
46+
SlotRear,
47+
SlotSlot
4248
},
4349
data () {
4450
return {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<template>
2+
<el-form size="small">
3+
<schema-form
4+
:model="model"
5+
:schema="schema"
6+
>
7+
<div slot="name">
8+
<span>姓名</span>
9+
<el-tooltip content="请输入用户姓名" placement="right">
10+
<i class="el-icon-warning"></i>
11+
</el-tooltip>
12+
</div>
13+
</schema-form>
14+
</el-form>
15+
</template>
16+
17+
<script>
18+
export default {
19+
data () {
20+
return {
21+
model: {
22+
name: ''
23+
},
24+
schema: [
25+
[
26+
{
27+
type: 'input',
28+
prop: 'name',
29+
formItem: { label: '' },
30+
frontSlot: 'name'
31+
}
32+
]
33+
]
34+
}
35+
}
36+
}
37+
</script>
38+
39+
<style scoped>
40+
41+
</style>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<template>
2+
<el-form size="small">
3+
<schema-form
4+
:model="model"
5+
:schema="schema"
6+
>
7+
<div slot="name" class="text-area">
8+
<span class="text-area__num">{{model.name.length}}</span>字
9+
</div>
10+
</schema-form>
11+
</el-form>
12+
</template>
13+
14+
<script>
15+
16+
export default {
17+
data () {
18+
return {
19+
model: {
20+
name: ''
21+
},
22+
schema: [
23+
[
24+
{
25+
type: 'input',
26+
prop: 'name',
27+
formItem: { label: '姓名' },
28+
rearSlot: 'name'
29+
}
30+
]
31+
]
32+
}
33+
}
34+
}
35+
</script>
36+
37+
<style scoped>
38+
.text-area{
39+
text-align: right;
40+
}
41+
.text-area__num{
42+
margin-right:5px;
43+
}
44+
</style>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<el-form size="small">
3+
<schema-form
4+
:model="model"
5+
:schema="schema"
6+
>
7+
<el-form-item label="活动名称" slot="name">
8+
<el-input v-model="model.name"></el-input>
9+
</el-form-item>
10+
</schema-form>
11+
</el-form>
12+
</template>
13+
14+
<script>
15+
export default {
16+
data () {
17+
return {
18+
model: {
19+
name: ''
20+
},
21+
schema: [
22+
[{ slot: 'name' }]
23+
]
24+
}
25+
}
26+
}
27+
</script>
28+
29+
<style scoped>
30+
31+
</style>

docs/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ module.exports = {
4141
children: [
4242
'/guide/component/SchemaForm',
4343
['/guide/component/schema', 'schema 详解'],
44-
['/guide/component/layout', 'layout 布局']
44+
['/guide/component/layout', 'layout 布局'],
45+
['/guide/component/slot', 'slot 插槽']
4546
]
4647
}
4748
]

docs/guide/component/schema.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,11 @@ on: {
113113
}
114114
```
115115

116-
## 插槽 slot
116+
## 插槽 slot
117117

118118
参数|说明|
119119
:--|:--
120120
slot| 自定义完整组件
121121
frontSlot| 定义element 组件前的插槽
122-
compSlot| 定义element 组件内的插槽
123122
rearSlot| 定义element 组件后的插槽
124123

docs/guide/component/slot.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### 插槽
2+
3+
<code-contain compName="SlotSlot" link="https://codesandbox.io/s/chacao-697j3?fontsize=14">
4+
<<< @/docs/.vuepress/components/slot-slot.vue
5+
</code-contain>
6+
7+
### 前置插槽
8+
9+
<code-contain compName="SlotFront" link="https://codesandbox.io/s/qianzhichacao-5phtv?fontsize=14">
10+
<<< @/docs/.vuepress/components/slot-front.vue
11+
</code-contain>
12+
13+
### 后置插槽
14+
15+
<code-contain compName="SlotRear" link="https://codesandbox.io/s/houzhichacao-vrkco?fontsize=14">
16+
<<< @/docs/.vuepress/components/slot-rear.vue
17+
</code-contain>

src/packages/SchemaForm.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
:model="model"
1919
:options="options"
2020
v-on="$listeners"
21-
/>
21+
>
22+
<slot v-if="col.frontSlot" :name="col.frontSlot" :slot="col.frontSlot"></slot>
23+
<slot v-if="col.rearSlot" :name="col.rearSlot" :slot="col.rearSlot"></slot>
24+
</schema-form-item>
2225
</template>
2326
</el-col>
2427
</template>

src/packages/SchemaFormItem.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
:onEvents="col.on"
1313
:options="options[col.prop]"
1414
>
15-
<slot :name="col.compSlot" v-if="col.compSlot"></slot>
1615
</component>
1716
<slot :name="col.rearSlot" v-if="col.rearSlot"></slot>
1817
</el-form-item>

0 commit comments

Comments
 (0)