uView组件库使用
- 安装配置uview
文档](https://www.uviewui.com/components/npmSetting.html)) - 在页面组件中,直接调用uview组件
<u-divider border-color="#ff5500">热门活动</u-divider>
uniapp的跨端效果演示
公司使用uniapp开发项目的时候,会优先对标考虑某个平台,我们在开发阶段,优先测试该平台
多测试兼容性较差的平台(微信小程序)
- web端
- 在manifest.json中配置资源路径,相当于配置vue项目的publicPath
- 将打包文件,部署至Nginx服务器
- 小程序端
- App端
- App图标配置
- 兼容处理(例如:App不允许在js中引入css)
- App内测平台
自定义组件封装
跟Vue中封装组件一样,引入、挂载、使用的方式,也一样
数据请求方式
方法1:使用uni.request
uni.request({url:'https://woniu.h5project.cn/1.1/classes/Job',method:'GET',header:{"X-LC-Id": "自己的id","X-LC-Key": "自己的key","Content-Type": "application/json"},success: (res) => {console.log(res);}})
方法2:自行封装uni.request
// promise的三种状态: pendding处理中 resolve成功 reject失败import {BASE_URL,ID,KEY} from '../config/index.js'function http({url,method="GET",data={}}){return new Promise((resolve,reject)=>{uni.request({url:BASE_URL+url,method,data,header:{'X-LC-Id': ID, //此处必须使用自己的ID'X-LC-Key': KEY, //此处必须使用自己的Key'Content-Type': 'application/json'},success:(res)=>{resolve(res) //交给then},fail:(err)=>{reject(err) //交给catch}})})}function get(url,data){return http({url,method:'GET',data})}function post(url,data){return http({url,method:'POST',data})}function del(url,data){return http({url,method:'DELETE',data})}export {http,get,post,del}
方法3:使用uView提供的方法
文档](https://www.uviewui.com/js/http.html))
axios不兼容小程序
- 在utils中封装了一个http.intercepter.js
- 在main.js中引入并使用http.intercepter.js
- 在组件中,使用uview提供的方法,请求数据
this.$u.get('/1.1/classes/Jobs').then(res=>{console.log(res);})
