tm-input.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view class="tm-input">
  3. <input class="inputArea" type="text" :value="inputValue" :placeholder="placeholder"
  4. @input="inputHandle"
  5. placeholder-style="font-size:25rpx;
  6. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  7. font-weight: 400;
  8. color: #B8BECC;"
  9. />
  10. <image @click="clearhandle" v-show="inputValue.length>0" class="clearIcon" src="../../static/clearIcon.png" mode=""></image>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: "tm-input",
  16. props: {
  17. placeholder: {
  18. type: String,
  19. default: () => {
  20. return '请输入'
  21. }
  22. },
  23. clear:{
  24. type: Boolean,
  25. default: () => {
  26. return false
  27. }
  28. }
  29. },
  30. data() {
  31. return {
  32. inputValue:''
  33. };
  34. },
  35. watch:{
  36. inputValue(val){
  37. this.$emit('onChange',val);
  38. },
  39. clear(val){
  40. if(val){
  41. this.inputValue = ''
  42. }
  43. }
  44. },
  45. methods:{
  46. inputHandle(event){
  47. this.inputValue = event.target.value
  48. },
  49. clearhandle(){
  50. this.inputValue = ''
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="less" scoped>
  56. .tm-input {
  57. position: relative;
  58. .inputArea {}
  59. .clearIcon {
  60. position: absolute;
  61. right:25rpx;
  62. top:50%;
  63. width:25rpx;
  64. height: 25rpx;
  65. margin-top: -12.5rpx;
  66. }
  67. }
  68. </style>