Key.js 996 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { use } from '../utils';
  2. import { preventDefault } from '../utils/event';
  3. var _use = use('key'),
  4. sfc = _use[0],
  5. bem = _use[1];
  6. export default sfc({
  7. props: {
  8. type: Array,
  9. text: [String, Number]
  10. },
  11. data: function data() {
  12. return {
  13. active: false
  14. };
  15. },
  16. computed: {
  17. className: function className() {
  18. var types = this.type.slice(0);
  19. this.active && types.push('active');
  20. return bem(types);
  21. }
  22. },
  23. methods: {
  24. onFocus: function onFocus() {
  25. this.active = true;
  26. this.$emit('press', this.text);
  27. },
  28. onBlur: function onBlur(event) {
  29. preventDefault(event, true);
  30. this.active = false;
  31. }
  32. },
  33. render: function render(h) {
  34. var onBlur = this.onBlur;
  35. return h("i", {
  36. "class": ['van-hairline', this.className],
  37. "on": {
  38. "touchstart": this.onFocus,
  39. "touchmove": onBlur,
  40. "touchend": onBlur,
  41. "touchcancel": onBlur
  42. }
  43. }, [this.text]);
  44. }
  45. });