[关闭]
@richey 2017-12-05T12:33:51.000000Z 字数 3075 阅读 2306

webapp开发教程01

webapp vue vux rest


0.打包下载:云盘webapp目录

1.安装node.js、npm及sublime text3

2.安装vue的UI框架vux

用sublime打开工程文件夹,讲解文件结构
image_1buv64h5ug2d1s3vq5fnea19co9.png-216.1kB

3. iconfont图标库

4 webapp设计

-要点讲解
- vue文件讲解(template:编译为网页 script:编译为js)
- RESTful api与后台接口及页面数据接口
- 后台定时刷新数据
- 修改main.js
- 配色(他山之石,可以攻玉::))
https://www.iviewui.com/components/color

  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import FastClick from 'fastclick'
  5. import VueRouter from 'vue-router'
  6. import App from './App'
  7. import Home from './components/HelloFromVux'
  8. import { AjaxPlugin } from 'vux'
  9. Vue.use(AjaxPlugin)
  10. //this.$http.defaults.baseURL = '127.0.0.1:5000';
  11. Vue.use(VueRouter)
  12. const routes = [{
  13. path: '/',
  14. component: Home
  15. }]
  16. const router = new VueRouter({
  17. routes
  18. })
  19. FastClick.attach(document.body)
  20. Vue.config.productionTip = false
  21. /* eslint-disable no-new */
  22. new Vue({
  23. router,
  24. render: h => h(App)
  25. }).$mount('#app-box')
  1. <template>
  2. <div>
  3. <x-header class="header" :left-options="{showBack: false}">
  4. 物联网应用系统
  5. </x-header>
  6. <divider>
  7. 实时数据
  8. </divider>
  9. <grid>
  10. <grid-item >
  11. <ul class="grid">
  12. <li
  13. <span class="grid-iot-icon" slot="icon" >&#xe604;</span>
  14. </li>
  15. <li class = "grid-text1">气温(℃)</li>
  16. <li class = "grid-text2"> {{my_data.temperature}}</li>
  17. </ul>
  18. </grid-item>
  19. <grid-item >
  20. <ul class="grid">
  21. <li
  22. <span class="grid-iot-icon" slot="icon" >&#xe63d;</span>
  23. </li>
  24. <li class = "grid-text1">湿度(%)</li>
  25. <li class = "grid-text2"> {{my_data.humidity}}</li>
  26. </ul>
  27. </grid-item>
  28. <grid-item >
  29. <ul class="grid">
  30. <li
  31. <span class="grid-iot-icon" slot="icon" >&#xe646;</span>
  32. </li>
  33. <li class = "grid-text1">电压(V)</li>
  34. <li class = "grid-text2"> {{my_data.voltage}}</li>
  35. </ul>
  36. </grid-item>
  37. </grid>
  38. </div>
  39. </template>
  40. <script>
  41. import { Group, Cell,Divider,XHeader,Flexbox,FlexboxItem,Grid, GridItem } from 'vux'
  42. export default {
  43. components: {
  44. Group,
  45. Cell,
  46. Divider,
  47. XHeader,
  48. Flexbox,
  49. FlexboxItem,
  50. Grid,
  51. GridItem
  52. },
  53. data () {
  54. return {
  55. // note: changing this line won't causes changes
  56. // with hot-reload because the reloaded component
  57. // preserves its current state and we are modifying
  58. // its initial state.
  59. msg: 'Hello World!',
  60. my_data:[],
  61. }
  62. },
  63. mounted() {
  64. this.getData();
  65. this.timerGetData = setInterval(this.getData, 3000);
  66. },
  67. beforeDestroy() {
  68. clearInterval(this.timerGetData)
  69. },
  70. methods: {
  71. getData() {
  72. this.$http({
  73. url: 'http://127.0.0.1:5000/voltage?id=12',
  74. method: 'GET',
  75. })
  76. .then((res) => {
  77. this.my_data = res.data;
  78. console.log('success ');
  79. }, (res) => {
  80. console.log('error ');
  81. });
  82. },
  83. }
  84. }
  85. </script>
  86. <style>
  87. .vux-demo {
  88. text-align: center;
  89. }
  90. .logo {
  91. width: 100px;
  92. height: 100px
  93. }
  94. .grid-iot-icon {
  95. font-family: 'iot';
  96. font-size: 32px;
  97. color: @theme-color;
  98. text-align: center;
  99. }
  100. .grid-text1 {
  101. text-align: center;
  102. color: grey;
  103. list-style-type:none;
  104. font-size: 18px;
  105. }
  106. .grid-text2 {
  107. text-align: center;
  108. color: black;
  109. list-style-type:none;
  110. font-size: 22px;
  111. }
  112. .grid {
  113. font-size: 22px;
  114. text-align: center;
  115. background-color: white;
  116. list-style-type:none;
  117. }
  118. .header {
  119. background-color: @theme-color;
  120. }
  121. </style>

image_1bvcqignm1vkkd7g199910ks1t3n13.png-291.8kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注