提交 3c2c054f 编写于 作者: H hdx

unicloud-db-contacts: 在 onLoad 中加载数据以加快显示

上级 8635bc49
<template> <template>
<scroll-view class="page"> <scroll-view class="page">
<unicloud-db ref="udb" v-slot:default="{data, loading, error}" :collection="collection" :where="where" <unicloud-db ref="udb" v-slot:default="{data, loading, error}" :collection="collection" :where="where"
loadtime="manual" page-data="replace"> page-data="replace">
<view v-if="error!=null" class="error">{{error.errMsg}}</view> <view v-if="error!=null" class="error">{{error.errMsg}}</view>
<view v-if="loading" class="loading">正在加载...</view> <view v-if="loading" class="loading">正在加载...</view>
<view v-if="data.length>0"> <view v-if="data.length>0">
...@@ -37,13 +37,14 @@ ...@@ -37,13 +37,14 @@
export default { export default {
data() { data() {
return { return {
collection: COLLECTION_NAME, collection: '',
where: '', where: '',
$whereID: '', $whereID: '',
$uniCloudElement: null as UniCloudDBElement | null $uniCloudElement: null as UniCloudDBElement | null
} }
}, },
onLoad(options : Map<string, string>) { onLoad(options : Map<string, string>) {
this.collection = COLLECTION_NAME;
this.$whereID = options.get('id') as string; this.$whereID = options.get('id') as string;
this.where = `_id=='${this.$whereID}'`; this.where = `_id=='${this.$whereID}'`;
}, },
...@@ -57,7 +58,6 @@ ...@@ -57,7 +58,6 @@
}, },
onReady() { onReady() {
this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement
this.$uniCloudElement!.loadData()
}, },
methods: { methods: {
displayGender(value : number | null) : string { displayGender(value : number | null) : string {
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
url: './edit?id=' + id url: './edit?id=' + id
}) })
}, },
onDataChange(id : string) { onDataChange(_ : string) {
this.$uniCloudElement!.loadData() this.$uniCloudElement!.loadData()
} }
} }
......
<template> <template>
<scroll-view class="scroll-view" :scroll-y="true"> <scroll-view class="scroll-view" :scroll-y="true">
<unicloud-db ref="udb" v-slot:default="{data, loading, error}" :collection="collection" :where="where" <unicloud-db ref="udb" v-slot:default="{data, loading, error}" :collection="collection" :where="where"
page-data="replace" loadtime="manual"> page-data="replace">
<view v-if="error!=null" class="error">{{error.errMsg}}</view> <view v-if="error!=null" class="error">{{error.errMsg}}</view>
<view v-if="loading" class="loading">正在加载...</view> <view v-if="loading" class="loading">正在加载...</view>
<form v-if="data.length>0" @submit="onFormSubmit"> <form v-if="data.length>0" @submit="onFormSubmit">
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
export default { export default {
data() { data() {
return { return {
collection: COLLECTION_NAME, collection: '',
where: '', where: '',
genderList: GenderList as GenderType[], genderList: GenderList as GenderType[],
$whereID: '', $whereID: '',
...@@ -54,12 +54,12 @@ ...@@ -54,12 +54,12 @@
} }
}, },
onLoad(options : Map<string, string>) { onLoad(options : Map<string, string>) {
this.collection = COLLECTION_NAME;
this.$whereID = options.get('id') as string; this.$whereID = options.get('id') as string;
this.where = `_id=='${this.$whereID}'`; this.where = `_id=='${this.$whereID}'`;
}, },
onReady() { onReady() {
this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement this.$uniCloudElement = this.$refs['udb'] as UniCloudDBElement
this.$uniCloudElement!.loadData()
}, },
methods: { methods: {
onFormSubmit: function (e : FormSubmitEvent) { onFormSubmit: function (e : FormSubmitEvent) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册