项目目录架构:

request.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| export default { get(url, data = {}, header = {}) { return this.request('GET', "http://127.0.0.1:8601"+url, data, header); },
post(url, data = {}, header = {}) { return this.request('POST', "http://127.0.0.1:8601"+url, data, header); },
request(method, url, data, header) { return new Promise((resolve, reject) => { uni.request({ url: url, method: method, data: data, header: header, success: (res) => { if (res.statusCode === 200) { resolve(res.data); } else { reject(res); } }, fail: (err) => { reject(err); } }); }); } }
|
修改下http的链接就行,这是向后端发送请求的封装
使用封装类例子
- GET(后端使用@RequestParam接收):
1 2 3
| request.get('/seat/getList?hall='+hall).then(res =>{ list.value = res.data })
|
- GET(后端使用@PathVariable接收):
1 2 3
| request.get('/seat/getList/'+hall).then(res =>{ list.value = res.data })
|
- POST(后端使用@RequestBody接收):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| const form = ref({ "line": '', "vertical": '', "hall": '' })
function submit(){ request.post('/seat/addHall',form.value).then(res =>{ if(res === "ok"){ toast.show('添加成功') }else{ toast.show('添加失败,或许已经有重复数据了?') } }) }
|
vue.config.js
1 2 3 4 5 6 7 8 9 10
| module.exports = { configureWebpack: { devServer: { disableHostCheck: true } } }
|
main.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import App from './App'
import Vue from 'vue' import './uni.promisify.adaptor' Vue.config.productionTip = false App.mpType = 'app' const app = new Vue({ ...App }) app.$mount()
import { createSSRApp } from 'vue' export function createApp() { const app = createSSRApp(App) return { app } }
|
就是HBuilder默认创建的
pages.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| { "easycom": { "autoscan": true, "custom": { "^wd-(.*)": "wot-design-uni/components/wd-$1/wd-$1.vue" } }, "pages": [ { "path": "pages/index/index", "style": { "navigationBarTitleText": "uni-app", "enablePullDownRefresh": true } }, { "path": "pages/index/test", "style": { "navigationBarTitleText": "uni-app2" } } ], "globalStyle": { "navigationBarTextStyle": "black", "navigationBarTitleText": "uni-app", "navigationBarBackgroundColor": "#F8F8F8", "backgroundColor": "#F8F8F8" }, "uniIdRouter": {} }
|
第一个 easycom是引入的一个组件库:Wot Design Uni | 一个基于Vue3+TS开发的uni-app组件库,提供70+高质量组件,支持暗黑模式、国际化和自定义主题。 (wot-design-uni.cn)
其他的就是页面路由了,路由跳转:uni.navigateTo({url:”/pages/index/test”})
总结
一般会vue3就会uniapp了,反正我一天就可以上手写项目了.