code-input.js 1008 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. Component({
  2. /**
  3. * 组件的初始数据
  4. */
  5. data: {
  6. focusIndex: 0, // 光标所在位置
  7. value: '', // 实际输入的值
  8. focus: true, // 是否获得焦点
  9. password: '', //替换显示的值*
  10. },
  11. /**
  12. * 组件的方法列表
  13. */
  14. methods: {
  15. setValue(e) {
  16. console.log(e);
  17. // 设置光标
  18. var value = e.detail.value
  19. this.setData({
  20. value: value,
  21. focusIndex: value.length,
  22. focus: value.length < 4,
  23. password: '*'.repeat(value.length)
  24. })
  25. },
  26. inputBlur(e) {
  27. if (e.detail.value.length === 4) {
  28. this.triggerEvent('complated', {
  29. value: e.detail.value
  30. })
  31. console.log(this.data.value);
  32. console.log('哈哈哈');
  33. this.setData({
  34. value: ''
  35. })
  36. let e = {
  37. detail: {
  38. value: ''
  39. }
  40. }
  41. this.setValue(e)
  42. console.log('呵呵呵');
  43. console.log(this.data.value);
  44. }
  45. }
  46. }
  47. })