index.vue 2.3 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>
9
        <button type="primary"  @tap="testCallback">多次回调示例</button>
lizhongyi_'s avatar
lizhongyi_ 已提交
10 11 12 13 14
				<button type="primary"  @tap="testBuildinObject">内置对象语法测试</button>
			</view>
	</view>
</template>
<script>
15
	import { callWithJSONParam, callWithStringParam, callWithoutParam,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
	
	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({
50
							title:'uts插件uts-helloworld的onCallback方法:'+response,
lizhongyi_'s avatar
lizhongyi_ 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
							icon:'none'
						});
					},
				);
			},
			/**
			 * 测试json参数回调
			 */
			testDoSthWithJSON: function () {
				var inputObject = {
					inputText:this.stringParam,
					errCode:0
				}
				
				callWithJSONParam({
					input:inputObject,
					success:function(response){
						uni.showToast({
							title:'执行结果:' + JSON.stringify(response),
							icon:'none'
						});
					}
				});
			},
75 76 77 78 79 80 81 82 83 84 85 86
      
      testCallback: function () {
				
				onCallback(
					function(response){
						uni.showToast({
							title:'uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:'+response,
							icon:'none'
						});
					},
				);
			},
lizhongyi_'s avatar
lizhongyi_ 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
			/**
			 * 测试内置对象
			 */
			testBuildinObject: function() {
				uni.navigateTo({
				    url: `/pages/index/basicTest`
				})
			}
			
		}
	}
</script>

<style>

  
</style>