uniapp开发技巧

时间格式化

			getTime(time) {
				// 比如需要这样的格式 yyyy-MM-dd hh:mm:ss
				console.log(time)
				let date = new Date(time * 1000);
				let Y = date.getFullYear() + '-';
				let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
				let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
				let m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
				let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
				return Y + M + D + h + m + s
				// 输出结果:2014-04-23 18:55:49
			},

uniapp获取上一页面的数据 

				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				let fromdata=prevPage.$vm.fromdata
				let data=obj[0]
				
				fromdata.comment=data.comment.join(";");
				fromdata.private_letter=data.private_letter.join(";");

下拉刷新

		//下拉刷新
		onPullDownRefresh() {
			this.is_update = true;
			this.page = 1;
			this.getYinliu();
		},
		onReachBottom() {
			if (this.has_more) {
				this.page = ++this.page;
				this.getYinliu();
			}
		}

uniapp导出表格就保存到手机 让后展示表格内容

			// 导出表格
			async exportTable(){
				console.log(this.choiceList,'----');
				if(this.choiceList.length==0){
					this.$u.toast('请勾选列表!');
					return;
				}
				var that = this
				//加载框动画
				uni.showLoading({title: '正在导出'});
				let res = await this.$api.getExport({ids:this.choiceList});
				if (res.code) {
					// 保存xls到手机
					uni.downloadFile({
						  url: res.data.url, 
						  success(res) {
							console.log('downloadFile',res)
							var filePath = res.tempFilePath
							uni.saveFile({
							  tempFilePath: filePath,
							  success: function (ress) {
								console.log('downloadFile1',ress)
								uni.showToast({
									icon: 'none',
									mask: true,
									title: '文件已保存:' + ress.savedFilePath, //保存路径
									duration: 3000,
								});
								
								var savedFilePath = ress.savedFilePath;
								uni.openDocument({
								  filePath: savedFilePath,
								  success: function(ress) {
									console.log('打开文档成功',ress)
									//隐藏加载框
									uni.hideLoading();
								  },
								  fail: function(err) {
									console.log('保存失败:', err)
								  }
								})
							  }
							});
			 
						  }
					})
					
					
				}
			},

uniapp开发技巧_第1张图片

 uniapp分包  超过2m分包

    "subPackages": 下设置分包内容  详细看官方文档

		"subPackages": [
           {
			"root": "pages/publish",
			"pages": [{
					"path": "channel",
					"title": "选择栏目",
					"style": {
						"navigationBarTitleText": "栏目",
						"navigationStyle": "custom",
						"navigationBarTextStyle": "white"
					}
				},
				{
					"path": "archives",
					"title": "发布文章",
					"style": {
						"navigationBarTitleText": "发布文章",
						"navigationStyle": "custom",
						"navigationBarTextStyle": "white",
						"app-plus": {
							"softinputMode": "adjustResize"
						}
					}
				},
				{
					"path": "diyform",
					"title": "自定义表单",
					"style": {
						"navigationBarTitleText": "自定义表单",
						"navigationStyle": "custom",
						"navigationBarTextStyle": "white",
						"app-plus": {
							"softinputMode": "adjustResize"
						}
					}
				}
			]
		}, 
           ]

你可能感兴趣的:(uni-app,数学建模)