test2.js 532 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // components/test2/test2.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. },
  8. /**
  9. * 组件的初始数据
  10. */
  11. data: {
  12. n1: 0,
  13. n2: 0,
  14. sum: 0
  15. },
  16. /**
  17. * 组件的方法列表
  18. */
  19. methods: {
  20. addN1() {
  21. this.setData({
  22. n1: this.data.n1 + 1
  23. })
  24. },
  25. addN2() {
  26. this.setData({
  27. n2: this.data.n2 + 1
  28. })
  29. }
  30. },
  31. observers: {
  32. 'n1, n2': function (newN1, newN2) {
  33. this.setData({
  34. sum: newN1 + newN2
  35. })
  36. }
  37. }
  38. })