1. uni-app 数据为空显隐

  1. <span v-if="data”>{data.name}</span>
  2. <span v-else>暂无数据</span>

2. 页面的滑动

https://www.cnblogs.com/chengmingxiaowu/p/10812008.html

  1. <view class="relative" @touchmove="handletouchmove" @touchstart="handletouchstart" @touchend="handletouchend">
  2. </view>
  1. data() {
  2. return {
  3. flag: 0,
  4. text: '',
  5. lastX: 0,
  6. lastY: 0
  7. }
  8. },
  9. methods: {
  10. handletouchmove: function(event) {
  11. // console.log(event)
  12. if (this.flag !== 0) {
  13. return;
  14. }
  15. let currentX = event.touches[0].pageX;
  16. let currentY = event.touches[0].pageY;
  17. let tx = currentX - this.lastX;
  18. let ty = currentY - this.lastY;
  19. let text = '';
  20. this.mindex = -1;
  21. //左右方向滑动
  22. if (Math.abs(tx) > Math.abs(ty)) {
  23. if (tx < 0) {
  24. text = '向左滑动';
  25. this.flag = 1;
  26. // this.getList(); //调用列表的方法
  27. } else if (tx > 0) {
  28. text = '向右滑动';
  29. this.flag = 2;
  30. }
  31. }
  32. //上下方向滑动
  33. else {
  34. if (ty < 0) {
  35. text = '向上滑动';
  36. this.flag = 3;
  37. // this.getList(); //调用列表的方法
  38. } else if (ty > 0) {
  39. text = '向下滑动';
  40. this.flag = 4;
  41. }
  42. }
  43. //将当前坐标进行保存以进行下一次计算
  44. this.lastX = currentX;
  45. this.lastY = currentY;
  46. this.text = text;
  47. },
  48. handletouchstart: function(event) {
  49. // console.log(event)
  50. this.lastX = event.touches[0].pageX;
  51. this.lastY = event.touches[0].pageY;
  52. },
  53. handletouchend: function(event) {
  54. this.flag = 0;
  55. this.text = '没有滑动';
  56. },
  57. }

3. 显示提示框

https://blog.csdn.net/zhuoganliwanjin/article/details/81872358

4. 获取设备基本配置

  1. onLoad(e) {
  2. let that = this;
  3. uni.getSystemInfo({
  4. success(res){
  5. console.log(res)
  6. that.WinHeight = res.windowHeight;
  7. }
  8. })
  9. },

5. 页面刷新属性

page.json中为需要的页面开启下拉刷新

  1. "enablePullDownRefresh": true

页面中,相当于onload()方法,监测顶端下拉刷新,处理完数据,停止刷新

  1. onPullDownRefresh(){
  2. console.log("顶部刷新");
  3. this.pageSize = 5;
  4. this.getAllEquipment(this.pageSize) // 调配方法
  5. uni.stopPullDownRefresh();
  6. }

6. JavaScript Date

获取昨日,今日,明日

  1. getNowFormatDate() {
  2. //昨天的时间
  3. var day1 = new Date();
  4. day1.setTime(day1.getTime()-24*60*60*1000);
  5. this.yesterday = day1.getFullYear()+ "-" + ((day1.getMonth()+1)<10?"0":"")+(day1.getMonth()+1)+ "-" +(day1.getDate()<10?"0":"")+(day1.getDate())
  6. //今天的时间
  7. var day2 = new Date();
  8. day2.setTime(day2.getTime());
  9. this.currentdate = day2.getFullYear()+ "-" + ((day2.getMonth()+1)<10?"0":"")+(day2.getMonth()+1)+ "-" +(day2.getDate()<10?"0":"")+(day2.getDate())
  10. //明天的时间
  11. var day3 = new Date();
  12. day3.setTime(day3.getTime()+24*60*60*1000);
  13. this.tomorrow = day3.getFullYear()+ "-" + ((day3.getMonth()+1)<10?"0":"")+(day3.getMonth()+1)+ "-" +(day3.getDate()<10?"0":"")+(day3.getDate())
  14. }

7.Uni-app_uCharts

https://blog.csdn.net/weixin_42551781/article/details/98348357

8. Promise 解决异步操作

Promise 是异步编程的一种解决方案,其实是一个构造函数,自己身上有all、reject、resolve这几个方法,原型上有then、catch等方法。

  1. new Promise(function () {});

9. Uni-app 弹出层popup

  1. <button type="button" @click="togglePopup('top')">顶部弹出 popup</button>
  2. <uni-popup :show="type === 'top'" position="top" mode="fixed" msg="顶部弹出popup" @hidePopup="togglePopup('')" >
  3. aaa
  4. </uni-popup>

10. uni-app 页面跳转

页面之间跳转+传值

  1. uni.navigateTo({
  2. url:'../page/page1?index='+this.params
  3. // url:'页面?参数='+值
  4. });

页面的获取参数值

  1. onLoad: function(options){
  2. this.paramsName = options.index;
  3. console.log(this.paramsName);
  4. },

11. app顶部透明度的改变

page.json 页面中添加titleNView的类型即可

  1. "style": {
  2. "app-plus": {
  3. "bounce": "none",
  4. "titleNView": {
  5. "type": "transparent",
  6. k }
  7. }
  8. }

12. 设置顶部title

  1. let title = "Uni-app";
  2. uni.setNavigationBarTitle({
  3. title
  4. })

13. 标题栏的点击效果

标题栏的内容写在page.json的情况下

  1. // 获取标题栏的input
  2. onNavigationBarSearchInputClicked:async function (){
  3. console.log("点击了输入框")
  4. }
  5. // 获取标题的按钮
  6. onNavigationBarButtonTap(e){
  7. console.log(e);
  8. let index = e.index;
  9. }

14. iconfont 的引用

www.iconfont.cn 官网创建账号,新建项目,下载至本地,将ttf放入到static 文件夹

在App.vue 中进行引入全局icon,直接在 app.vue 里面加入css的文件即可

在VUE中进行引用的时候

15. app顶部按钮

顶部按钮配置在page.json

  1. onNavigationBarButtonTap(e) {
  2. // 根据e.index来判断是哪一个按钮,进行相应事件
  3. const index = e.index;
  4. if (index === 0) {
  5. this.$api.msg('点击返回按钮');
  6. uni.navigateBack({
  7. delta:1
  8. })
  9. } else if (index === 1) {
  10. console.log("点击改变地区按钮")
  11. this.$refs['region'].show() // 底部多列选项卡显示
  12. }
  13. }

16. 弹出键盘对页面的压缩

  1. <view class="container" :style="'height:'+screenHeight+'px !important;'" >
  1. @import "../../static/css/login.scss";
  2. .container{
  3. width: 100%;
  4. height: 100%;
  5. background: url('../../static/login.png') no-repeat;
  6. background-size: 100% 100%;
  7. }
  1. data() {
  2. return {
  3. screenHeight:''
  4. }
  5. },
  6. onload(){
  7. this.screenHeight = uni.getSystemInfoSync().windowHeight;
  8. console.log(this.screenHeight)
  9. }