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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
<button type="primary" @tap="btn">登录</button> //判断信息是否填写 btn() { if (this.username.length <= 0) { uni.showToast({ icon: 'none', title: '请输入用户名' }); return; } if (this.pwd.length <= 0) { uni.showToast({ icon: 'none', title: '请输入密码' }); return; } } //登陆 uni.request({ url: 'http://199.168.100.55:54723/ZycfService/login/login', //仅为示例,并非真实接口地址。 data: { username: this.username, pass: this.pwd },success: (res) => { let list=JSON.stringify(res.data); console.log("返回数据状态:" + list); if(list=="[]"){ uni.showToast({ icon: 'none', title: '用户名或密码错误' }); return; } uni.showToast({ icon: 'none', title: '登录成功' }); },fail: () => { uni.showToast({ icon: 'none', title: '网络异常,请稍后重试' }); } }) //加入缓存 uni.setStorage({ key:'userinfo', data:{ bh:_this.lists[0]['bh'], rolename:_this.lists[0]['rolename'], username:_this.lists[0]['username'] } }) //跳转 uni.navigateTo({ url: '../home/home', }); onLoad() { //首先将实例指针保存到全局变量 _this 方便在异步请求中访问实例本身 _this = this; uni.getStorage({ key: 'userinfo', success: function(res) { const listdata = res.data; _this.list = listdata; console.log("数据是:" + _this.list.username) } } --------------- uni.chooseImage({ count: 6, //可以选择图片的张数 sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 sourceType: ['album'], //从相册选择 默认是两个都有 success: function (res) { console.log(JSON.stringify(res.tempFilePaths)); //返回结果 } }); uni.previewImage(OBJECT) uni.chooseImage({ count: 6, sizeType: ['original', 'compressed'], success: function(res) { // 预览图片 // uni.previewImage({ // urls: res.tempFilePaths // }); for(var i=0;i< res.tempFilePaths.length;i++){ console.log("第"+i+"张图片路径:"+res.tempFilePaths[i]); } uni.getImageInfo({ src:res.tempFilePaths[0], success:function(image){ console.log("图片路径:"+image.path); } }); } }); } |
uni-app 常用写法
未经允许不得转载:王明昌博客 » uni-app 常用写法