index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view class="u-demo">
  3. <view class="u-demo-wrap">
  4. <view class="u-demo-title">演示效果</view>
  5. <view class="u-demo-area">
  6. <u-toast ref="uToast"></u-toast>
  7. <u-search v-model="value" @change="change" @custom="custom" @search="search" :shape="shape" :clearabled="clearabled"
  8. :show-action="showAction" :input-align="inputAlign" @clear="clear"></u-search>
  9. </view>
  10. </view>
  11. <view class="u-config-wrap">
  12. <view class="u-config-title u-border-bottom">
  13. 参数配置
  14. </view>
  15. <view class="u-config-item">
  16. <view class="u-item-title">初始值</view>
  17. <u-subsection :list="['空', '天山雪莲']" @change="valueChange"></u-subsection>
  18. </view>
  19. <view class="u-config-item">
  20. <view class="u-item-title">搜索框形状</view>
  21. <u-subsection :list="['圆形', '方形']" @change="shapeChange"></u-subsection>
  22. </view>
  23. <view class="u-config-item">
  24. <view class="u-item-title">清除控件</view>
  25. <u-subsection :list="['启用', '关闭']" @change="clearabledChange"></u-subsection>
  26. </view>
  27. <view class="u-config-item">
  28. <view class="u-item-title">右侧控件</view>
  29. <u-subsection :list="['启用', '关闭']" @change="showActionChange"></u-subsection>
  30. </view>
  31. <view class="u-config-item">
  32. <view class="u-item-title">水平对齐方式</view>
  33. <u-subsection :list="['左', '中', '右']" @change="inputAlignChange"></u-subsection>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. value: '',
  43. shape: 'round',
  44. clearabled: true,
  45. showAction: true,
  46. inputAlign: 'left'
  47. }
  48. },
  49. watch: {
  50. // 这里的演示为证明通过v-model绑定值,它是双向绑定的,意味着您无需监听change事件
  51. // 也能知道value值当前的内容
  52. value(val) {
  53. // console.log(val);
  54. }
  55. },
  56. methods: {
  57. valueChange(index) {
  58. this.value = index == 0 ? '' : '天山雪莲';
  59. },
  60. shapeChange(index) {
  61. this.shape = index == 0 ? 'round' : 'square';
  62. },
  63. clearabledChange(index) {
  64. this.clearabled = index == 0 ? true : false;
  65. },
  66. showActionChange(index) {
  67. this.showAction = index == 0 ? true : false;
  68. },
  69. inputAlignChange(index) {
  70. this.inputAlign = index == 0 ? 'left' : index == 1 ? 'center' : 'right';
  71. },
  72. change(value) {
  73. // 搜索框内容变化时,会触发此事件,value值为输入框的内容
  74. //console.log(value);
  75. },
  76. custom(value) {
  77. //console.log(value);
  78. this.$u.toast('输入值为:' + value)
  79. },
  80. search(value) {
  81. this.$refs.uToast.show({
  82. title: '搜索内容为:' + value,
  83. type: 'success'
  84. })
  85. },
  86. clear() {
  87. // console.log(this.value);
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .u-demo {}
  94. </style>