提交 d96b8a24 编写于 作者: 雪洛's avatar 雪洛

fix(uni-app-x web): 修复unicloud-db组件ssr时无法在服务端取数据的Bug

上级 62e4e002
......@@ -5,6 +5,9 @@ export type AutoImportOptions = Options
const uniPreset = {
from: '@dcloudio/uni-app',
imports: [
// ssr
'ssrRef',
'shallowSsrRef',
// uni-app lifecycle
// App and Page
'onShow',
......
......@@ -5,8 +5,6 @@
</template>
<script>
export default {
name: 'PageMeta',
setup(props, { emit }) {
}
name: 'PageMeta'
}
</script>
......@@ -190,7 +190,7 @@
} as UniCloudDBComponentUpdateOptions)
}
onLoadData! : (_ : UniCloudDBComponentLoadDataOptions) => void
onLoadData! : (_ : UniCloudDBComponentLoadDataOptions) => Promise<void>
onLoadMore! : () => void
onAdd! : (value : UTSJSONObject, options : UniCloudDBComponentAddOptions) => void
onUpdate!: (id : string, value : UTSJSONObject, options : UniCloudDBComponentUpdateOptions) => void
......@@ -288,11 +288,23 @@
manual: {
type: Boolean,
default: false
},
ssrKey: {
type: String,
default: ""
}
},
data() {
return {
//#ifdef WEB
// TODO 修复类型错误
// @ts-ignore
dataList: ssrRef([] as Array<UTSJSONObject>) as Array<UTSJSONObject>,
//#endif
//#ifndef WEB
dataList: [] as Array<UTSJSONObject>,
//#endif
// dataList: [] as Array<UTSJSONObject>,
loading: false,
hasMore: false,
isEnded: false,
......@@ -304,18 +316,27 @@
error: null as UniCloudError | null
}
},
//#ifdef (WEB || APP-IOS) && !_NODE_JS_
//#ifdef WEB || APP-IOS
beforeCreate() {
if (!registerFlag) {
registerFlag = true
// @ts-ignore
customElements.define(
typeof customElements !== 'undefined' && customElements.define(
'uni-cloud-db-element',
UniCloudDBElement,
)
}
},
//#endif
//#ifdef WEB
async serverPrefetch() : Promise<any> {
// @ts-ignore
if (!this.manual && this.loadtime === 'auto') {
// @ts-ignore
return this.loadData({})
}
},
//#endif
created() {
this.pagination.current = this.pageCurrent
this.pagination.size = this.pageSize
......@@ -359,7 +380,7 @@
}
)
if (!this.manual && this.loadtime == LOAD_MODE_AUTO) {
if (!this.manual && this.loadtime == LOAD_MODE_AUTO && this.dataList.length === 0) {
if (typeof this.collection == 'string') {
const collectionString = this.collection as string
if (collectionString.length == 0) {
......@@ -394,7 +415,7 @@
//#endif
},
methods: {
loadData(options : UniCloudDBComponentLoadDataOptions) {
async loadData(options : UniCloudDBComponentLoadDataOptions) : Promise<void> {
let clear = (options.clear != null && options.clear == true)
if (clear == true) {
if (this.pageData == PAGE_MODE_REPLACE) {
......@@ -403,7 +424,7 @@
this.reset()
}
this.get(options)
await this.get(options)
},
loadMore() {
if (this.isEnded || this.loading) {
......@@ -427,7 +448,7 @@
reset() {
this.pagination.current = 1
},
get(options? : UniCloudDBComponentLoadDataOptions) {
async get(options? : UniCloudDBComponentLoadDataOptions) : Promise<void> {
let loadAfterClear = false
if (options != null && options.clear != null && options.clear == true) {
loadAfterClear = true
......@@ -439,7 +460,7 @@
this.error = null
this.loading = true
this.getExec().then((res : UniCloudDBGetResult) => {
await this.getExec().then((res : UniCloudDBGetResult) => {
const data = res.data
const count = res.count
......
......@@ -60,7 +60,7 @@ export function initPlugins(
config,
extend({ exclude: [...COMMON_EXCLUDE, /\/@dcloudio\/uni-app/] }, options)
),
'vite:vue'
process.env.UNI_APP_X === 'true' ? 'uts' : 'vite:vue'
)
addPlugin(plugins, uniJsonPlugin(options), 'vite:json', 'pre')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册