index.uvue 2.8 KB
Newer Older
lizhongyi_'s avatar
lizhongyi_ 已提交
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
<template>
    <view>
        <page-head :title="title"></page-head>
        <input class="uni-input" v-model="stringParam" />
        <view class="uni-btn-v uni-common-mt">
            <button type="primary" @tap="testDoSthWithCallback">uts异步方法(无参数)</button>
            <button type="primary" @tap="testDoSthWithString">uts异步方法(字符串参数)</button>
            <button type="primary" @tap="testDoSthWithJSON">uts异步方法(json参数)</button>
			<button type="primary"  @tap="testBuildinObject">内置对象语法测试</button>
        </view>
    </view>
</template>
<script>
    import { callWithJSONParam, callWithStringParam, callWithoutParam, JsonParamOptions, inputJSON } from "../../uni_modules/uts-helloworld";

    export default {
        data() {
            return {
                title: 'UTS入门示例',
                stringParam: "hello world",
            }
        },

        methods: {

            /**
             * 测试无参数调用
             */
            testDoSthWithCallback: function () {

                callWithoutParam(
                    () => {
                        uni.showToast({
                            title: '成功调用uts插件uts-helloworld的callWithoutParam',
                            icon: 'none'
                        });
                    }
                );
            },
            /**
             * 测试字符串参数回调
             */
            testDoSthWithString: function () {

                callWithStringParam(
                    this.stringParam,
                    function (response) {
                        uni.showToast({
                            title: 'uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:' + response,
                            icon: 'none'
                        });
                    },
                );
            },
            /**
             * 测试json参数回调
             */
            testDoSthWithJSON: function () {
                const that = this
                var inputObject : inputJSON = {
                    inputText: that.stringParam,
                    errCode: 0
                }

                callWithJSONParam({
                    input: inputObject,
                    success: function (response) {
                        uni.showToast({
                            title: '执行结果:' + JSON.stringify(response),
                            icon: 'none'
                        });
                    }
                } as JsonParamOptions);
            },
			/**
			 * 测试内置对象
			 */
			testBuildinObject: function() {
				uni.navigateTo({
				    url: `/pages/index/basicTest`
				})
			}

        }
    }
</script>

<style>


</style>