deviceInfo.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <view class="device-info">
  3. <text v-for="(item,index) in infoList" :key="index" space="ensp" class="t">
  4. {{item.key}} : {{item.element}}
  5. </text>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. components: {},
  11. data: () => ({
  12. index:0,
  13. list:[]
  14. }),
  15. computed: {
  16. infoList(){
  17. if(this.$store.state.moduleMqtt.deviceList.length > this.index){
  18. let object = this.$store.state.moduleMqtt.deviceList[this.index]
  19. let list = []
  20. for (const key in object) {
  21. if (Object.hasOwnProperty.call(object, key)) {
  22. const element = object[key];
  23. list.push({
  24. key,
  25. element,
  26. })
  27. }
  28. }
  29. return list
  30. }else{
  31. return []
  32. }
  33. }
  34. },
  35. methods: {
  36. getInfoList(){
  37. console.log(`getInfoList1 ${this.$store.state.moduleMqtt.deviceList.length} index = ${this.index}` );
  38. if(this.$store.state.moduleMqtt.deviceList.length > this.index){
  39. console.log("getInfoList2");
  40. let object = this.$store.state.moduleMqtt.deviceList[this.index]
  41. let list = []
  42. for (const key in object) {
  43. if (Object.hasOwnProperty.call(object, key)) {
  44. const element = object[key];
  45. list.push({
  46. key:key,
  47. element:element,
  48. })
  49. }
  50. }
  51. console.log(list);
  52. this.list = list
  53. }
  54. }
  55. },
  56. watch: {},
  57. // 页面周期函数--监听页面加载
  58. onLoad(options) {
  59. // if(options){
  60. // this.index = Number.parseInt(options.index)
  61. // }
  62. //this.getInfoList()
  63. },
  64. // 页面周期函数--监听页面初次渲染完成
  65. onReady() {},
  66. // 页面周期函数--监听页面显示(not-nvue)
  67. onShow() {},
  68. // 页面周期函数--监听页面隐藏
  69. onHide() {},
  70. // 页面周期函数--监听页面卸载
  71. onUnload() {},
  72. // 页面处理函数--监听用户下拉动作
  73. onPullDownRefresh() {
  74. uni.stopPullDownRefresh();
  75. },
  76. // 页面处理函数--监听用户上拉触底
  77. onReachBottom() {},
  78. // 页面处理函数--监听页面滚动(not-nvue)
  79. /* onPageScroll(event) {}, */
  80. // 页面处理函数--用户点击右上角分享
  81. /* onShareAppMessage(options) {}, */
  82. };
  83. </script>
  84. <style>
  85. .device-info{
  86. display: flex;
  87. flex-direction: column;
  88. }
  89. .t{
  90. margin: 10rpx;
  91. }
  92. </style>