call-function.uvue 1.4 KB
Newer Older
雪洛's avatar
雪洛 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<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" @click="callFunction">请求云函数</button>
        </view>
      </view>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>
<script>
  export default {
    data() {
      return {
        title: 'uniCloud.callFunction'
      }
    },
    onLoad() {
    },
    onUnload() {
    },
    methods: {
      callFunction: function () {
        uni.showLoading({
          title: '加载中...'
        })
        uniCloud.callFunction({
          name: 'echo-cf',
          data: {
            num: 1,
            str: 'ABC'
          } as UTSJSONObject
        }).then<void>(res => {
          const result = res.result
          console.log(JSON.stringify(result))
          uni.hideLoading()
          uni.showModal({
            title: '提示',
            content: result['showMessage'] as string,
            showCancel: false
          })
        }).catch<void>((err: UniCloudError) => {
          uni.hideLoading()
          uni.showModal({
            title: '错误',
            content: err.errMsg,
            showCancel: false
          })
        })
      }
    }
  }
</script>

<style>
</style>