设置组件的插槽 slot

默认插槽

设置组件的默认插槽

::: demo

  1. <template>
  2. <div>
  3. <form-create :rule="rule" v-model="fApi" :option="options"/>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. data(){
  9. return {
  10. fApi:{},
  11. options:{
  12. onSubmit:(formData)=>{
  13. alert(JSON.stringify(formData));
  14. },
  15. submitBtn:false,
  16. resetBtn:false
  17. },
  18. rule:[
  19. {
  20. type:'el-button',
  21. children:['方式1']
  22. },
  23. {
  24. type:'el-button',
  25. children:[{
  26. type:'i',
  27. class:'el-icon-check'
  28. },' 方式2']
  29. }
  30. ]
  31. }
  32. }
  33. }
  34. </script>

:::

指定插槽

给input组件通过prefixsuffix插槽设置前缀及后缀图标

::: demo

  1. <template>
  2. <div>
  3. <form-create :rule="rule" v-model="fApi" :option="options"/>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. data(){
  9. return {
  10. fApi:{},
  11. options:{
  12. onSubmit:(formData)=>{
  13. alert(JSON.stringify(formData));
  14. },
  15. submitBtn:false,
  16. resetBtn:false
  17. },
  18. rule:[
  19. {
  20. type: 'input',
  21. field: 'input',
  22. title: '插槽',
  23. children: [
  24. {
  25. type:'i',
  26. class:'el-icon-check',
  27. slot: 'prefix',
  28. },
  29. {
  30. type:'i',
  31. class:'el-icon-check',
  32. slot: 'suffix',
  33. },
  34. ]
  35. }
  36. ]
  37. }
  38. }
  39. }
  40. </script>

:::