index.uvue 3.4 KB
Newer Older
lizhongyi_'s avatar
lizhongyi_ 已提交
1 2 3 4 5 6 7 8
<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>
杜庆泉's avatar
杜庆泉 已提交
9 10
            <button type="primary"  @tap="testCallback">多次回调示例</button>
            <button type="primary"  @tap="testBuildinObject">内置对象语法测试</button>
lizhongyi_'s avatar
lizhongyi_ 已提交
11 12 13 14
        </view>
    </view>
</template>
<script>
杜庆泉's avatar
杜庆泉 已提交
15
    import { callWithJSONParam, callWithStringParam, callWithoutParam, JsonParamOptions, inputJSON ,onCallback} from "../../uni_modules/uts-helloworld";
lizhongyi_'s avatar
lizhongyi_ 已提交
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

    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);
            },
杜庆泉's avatar
杜庆泉 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
            testCallback: function () {
            	
            	onCallback(
            		function(response){
            			uni.showToast({
            				title:'uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:'+response,
            				icon:'none'
            			});
            		},
            	);
            },
            /**
             * 测试内置对象
             */
            testBuildinObject: function() {
              uni.navigateTo({
                  url: `/pages/index/basicTest`
              })
            }
        
lizhongyi_'s avatar
lizhongyi_ 已提交
96 97 98 99 100 101 102 103
        }
    }
</script>

<style>


</style>