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

Revert "Revert "feat: add import object demo""

This reverts commit a1f34f14.
上级 7376b176
...@@ -672,6 +672,12 @@ ...@@ -672,6 +672,12 @@
"navigationBarTitleText": "" "navigationBarTitleText": ""
} }
}, },
{
"path": "pages/API/import-object/import-object",
"style": {
"navigationBarTitleText": ""
}
},
{ {
"path": "pages/API/get-system-info/get-system-info", "path": "pages/API/get-system-info/get-system-info",
"style": { "style": {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
export default { export default {
data() { data() {
return { return {
title: 'uniCloud.callFunction' title: '请求云函数'
} }
}, },
onLoad() { onLoad() {
......
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="addTodo">添加Todo</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="randomFail">随机触发失败重试</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="fail">云对象失败调用</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="success">云对象成功调用</button>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: '请求云对象'
}
},
methods: {
addTodo() {
const todo = uniCloud.importObject('todo')
const title = '学习编程'
const content = '熟悉uts语法'
todo.add(title, content).then<void>((res: UTSJSONObject) : void => {
uni.showModal({
title: '错误',
content: res['showMessage'] as string,
showCancel: false
})
}).catch<void>((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
})
},
randomFail() {
const todoObj = uniCloud.importObject('todo', {
errorOptions: {
retry: true
}
})
todoObj.randomFail().then<void>((res: UTSJSONObject) : void => {
uni.showModal({
title: '错误',
content: res['showMessage'] as string,
showCancel: false
})
}).catch<void>((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
})
},
fail() {
const todo = uniCloud.importObject('todo')
todo.fail().then<void>((res: UTSJSONObject) : void => {
uni.showModal({
title: '错误',
content: 'todo.fail应调用失败,此处错误的触发了成功回调',
showCancel: false
})
console.log('todo.fail: ', res);
}).catch<void>((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
})
},
success() {
const todo = uniCloud.importObject('todo')
todo.success().then<void>((res: UTSJSONObject) : void => {
uni.showModal({
title: '错误',
content: res['showMessage'] as string,
showCancel: false
})
}).catch<void>((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
})
}
}
}
</script>
<style>
</style>
...@@ -385,6 +385,10 @@ ...@@ -385,6 +385,10 @@
name: '云函数', name: '云函数',
url: 'call-function', url: 'call-function',
}, },
{
name: '云对象',
url: 'import-object',
},
] as Page[], ] as Page[],
}, },
/* { /* {
......
// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程:https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
module.exports = {
async add(title, content) {
console.log(title, content)
return {
showMessage: `Todo added, title: ${title}, content: ${content}`
}
},
async randomFail() {
const random = Math.random()
console.log(random);
if (random > 0.5) {
return {
errCode: 'RANDOM_FAIL',
errMsg: 'todo.randomFail failed'
}
} else {
return {
errCode: 0,
errMsg: '',
showMessage: 'todo.randomFail successed'
}
}
},
async fail() {
return {
errCode: 'TEST_ERROR_CODE',
errMsg: 'todo.fail failed',
}
},
async success() {
return {
errCode: 0,
errMsg: '',
showMessage: 'todo.success successed'
}
}
}
{
"name": "todo",
"dependencies": {},
"extensions": {
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册