列表页放置监听

fabClick() {
				// 打开新增页面
				uni.navigateTo({
					url: './add',
					events: {
						// 监听新增数据成功后, 刷新当前页面数据
						refreshData: () => {
							this.$refs.udb.loadData({
								clear: true
							})
						}
					}
				})
			}

编辑或新增页处理成功后,刷新列表

/**
 * 提交表单
 */
submitForm(value) {
	// 使用 clientDB 提交数据
	return db.collection(dbCollectionName).add(value).then((res) => {
		uni.showToast({
			icon: 'none',
			title: '新增成功'
		})
		this.getOpenerEventChannel().emit('refreshData')
		setTimeout(() => uni.navigateBack(), 500)
	}).catch((err) => {
		uni.showModal({
			content: err.message || '请求服务失败',
			showCancel: false
		})
	})
}

重要的是

events: {
	// 监听新增数据成功后, 刷新当前页面数据
	refreshData: () => {
		this.$refs.udb.loadData({
			clear: true
		})
	}
}

	this.getOpenerEventChannel().emit('refreshData')
	setTimeout(() => uni.navigateBack(), 500)
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐