uView组件库使用
- 安装配置uview
[文档]( - )
- 在页面组件中,直接调用uview组件
<u-divider border-color="#ff5500">热门活动</u-divider>
uniapp的跨端效果演示
公司使用uniapp开发项目的时候,会优先对标考虑某个平台,我们在开发阶段,优先测试该平台 多测试兼容性较差的平台(微信小程序)
- web端
- 在manifest.json中配置资源路径,相当于配置vue项目的publicPath
- 将打包文件,部署至Nginx服务器
- 小程序端
- App端
- App图标配置
- 兼容处理(例如:App不允许在js中引入css)
- App内测平台](https://www.betaqr.com/))
自定义组件封装
跟Vue中封装组件一样,引入、挂载、使用的方式,也一样
数据请求方式
方法1:使用uni.request
uni.request({url:'https://woniu.h5project.cn/1.1/classes/Jobs',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失败let mode = 'dev' //通过开发模式变量,动态切换baseUrllet baseUrl = '' //预先定义基础域名if(mode=='dev'){baseUrl='https://woniu.h5project.cn' //必须换成自己的LeanCloud域名}else{baseUrl = 'http://vip.com'}function fetchData({url,method='get',data={}}={}){return new Promise((resolve,reject)=>{uni.showLoading({title: '拼命加载中...',})// 方法1uni.request({url: baseUrl+url,method,data,header:{"X-LC-Id": "自己的id","X-LC-Key": "自己的key","Content-Type": "application/json"},success:(res)=>{uni.hideLoading()resolve(res) //成功后,将数据交付给then},fail:(err)=>{reject(err) //失败后,将数据交付给catch}})})}function get(url,data){ //基于fetchData二次封装getreturn fetchData({url,method:'get',data})}function post(url,data){return fetchData({url,method:'post',data})}function del(url,data){ //return fetchData({url,method:'delete',data})}module.exports = {fetchData,get,post,del}
方法3:使用uView提供的方法
axios不兼容小程序
- 在utils中封装了一个http.intercepter.js
- 在main.js中引入并使用http.intercepter.js
- 在组件中,使用uview提供的方法,请求数据
this.$u.get('/1.1/classes/Jobs').then(res=>{console.log(res);})
