desc.js 869 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // components/desc/desc.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. msg: {
  8. type: String,
  9. value: "暂无"
  10. }
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. data: {
  16. descText: ""
  17. },
  18. /* 生命周期 */
  19. lifetimes:{
  20. attached(){
  21. console.log(this.data.msg)
  22. this.formateDesc(this.data.msg)
  23. }
  24. },
  25. /**
  26. * 组件的方法列表
  27. */
  28. methods: {
  29. formateDesc(str){
  30. let _str = str
  31. if(str.length > 50){
  32. _str = str.substr(0,50)
  33. }
  34. console.log(_str)
  35. this.setData({
  36. descText: _str
  37. })
  38. },
  39. showMore(){
  40. this.setData({
  41. descText: this.data.msg
  42. })
  43. }
  44. }
  45. })