Crud 模块

搜索

搜索 - 图1

配置column数组对象中的search属性为true时,即可激活该字段的搜索功能,点击搜索功能回调search-change方法,返回搜索的参数,searchDefault表格搜索的默认值设置,通过设置searchShowfalse,首次加载时候不显示,点击搜索图标显示

  1. <avue-crud :data="data" :option="option0" @search-change="searchChange"></avue-crud>
  2. <script>
  3. export default {
  4. data() {
  5. return {
  6. data: [
  7. {
  8. name:'张三',
  9. sex:'男',
  10. grade:'0',
  11. date:'2018-08-08',
  12. time:'13:00:00'
  13. }, {
  14. name:'李四',
  15. sex:'女',
  16. grade:'1',
  17. date:'2018-08-09',
  18. time:'13:00:00'
  19. }
  20. ],
  21. option0:{
  22. page:false,
  23. align:'center',
  24. menuAlign:'center',
  25. searchMenuSpan:6,
  26. column:[
  27. {
  28. label:'姓名',
  29. prop:'name',
  30. search:true
  31. },
  32. {
  33. label:'性别',
  34. prop:'sex'
  35. },
  36. {
  37. label:'权限',
  38. prop:'grade',
  39. type:'select',
  40. searchDefault:[0],
  41. searchMmultiple:true,
  42. dicData:[
  43. {
  44. label:'会员',
  45. value:0
  46. },{
  47. label:'普通',
  48. value:1
  49. }
  50. ]
  51. }
  52. ]
  53. }
  54. };
  55. },
  56. methods: {
  57. searchChange(params){
  58. this.$message.success('搜索数据'+ JSON.stringify(params));
  59. },
  60. }
  61. }
  62. </script>

日期和时间范围

搜索 - 图2

配置moretrue时, typetimedatedatetime控件时他们全部变成范围筛选

  1. <avue-crud :data="data" :option="option1" @search-change="searchChange"></avue-crud>
  2. <script>
  3. export default {
  4. data() {
  5. return {
  6. data: [
  7. {
  8. name:'张三',
  9. sex:'男',
  10. date:'2018-08-08',
  11. time:'13:00:00'
  12. }, {
  13. name:'李四',
  14. sex:'女',
  15. date:'2018-08-09',
  16. time:'13:00:00'
  17. }
  18. ],
  19. option1:{
  20. page:false,
  21. align:'center',
  22. menuAlign:'center',
  23. searchMenuSpan:6,
  24. column:[
  25. {
  26. label:'姓名',
  27. prop:'name'
  28. },
  29. {
  30. label:'性别',
  31. prop:'sex',
  32. },
  33. {
  34. label:'日期',
  35. prop:'date',
  36. type:'date',
  37. more:true,
  38. search:true,
  39. },
  40. {
  41. label:'时间',
  42. prop:'time',
  43. type:'time'
  44. },
  45. ]
  46. },
  47. };
  48. },
  49. methods: {
  50. searchChange(params){
  51. this.$message.success('搜索数据'+ JSON.stringify(params));
  52. },
  53. }
  54. }
  55. </script>

自定义内容

搜索 - 图3

设置searchMenu为搜索按钮的卡槽自定义,设置卡槽名字为search即可,一定要加el-form-item否则格式排版会出问题,目前的排版为一次追加,不够的排到下一行,如果要清空数据,需要在search-reset回调中手动清空你自定义的数据,设置filterabletrue是可以输入搜索字典数据

  1. <avue-crud :data="data" :option="option" @search-reset="searchReset1" @search-change="searchChange1">
  2. <template slot="search">
  3. <el-form-item label="自定义">
  4. <el-input v-model="search.slot" placeholder="自定义搜索" size="small"/>
  5. </el-form-item>
  6. </template>
  7. <template slot="searchMenu">
  8. <el-button size="small">自定义按钮</el-button>
  9. </template>
  10. </avue-crud>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. search:{
  16. slot:''
  17. },
  18. data: [
  19. {
  20. name:'张三',
  21. sex:'男',
  22. date:'2018-08-08',
  23. time:'13:00:00'
  24. }, {
  25. name:'李四',
  26. sex:'女',
  27. date:'2018-08-09',
  28. time:'13:00:00'
  29. }
  30. ],
  31. option:{
  32. page:false,
  33. align:'center',
  34. menuAlign:'center',
  35. searchMenuSpan:6,
  36. column:[
  37. {
  38. label:'姓名',
  39. prop:'name',
  40. filterable:true,
  41. },
  42. {
  43. label:'性别',
  44. prop:'sex',
  45. search:true,
  46. }
  47. ]
  48. },
  49. };
  50. },
  51. methods: {
  52. searchChange1(params){
  53. this.$message.success('搜索数据'+ JSON.stringify(Object.assign(params,this.search)));
  54. },
  55. searchReset1(){
  56. this.search={};
  57. this.$message.success('清空回调')
  58. }
  59. }
  60. }
  61. </script>