setup.uvue 1.8 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
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
<template>
	<!-- #ifdef APP -->
	<scroll-view style="flex: 1">
	<!-- #endif -->
		<view class="page">
			<text class='uni-common-mt' id="str">str: {{ str }}</text>
			<text class='uni-common-mt' id="num">num: {{ num }}</text>
			<text class='uni-common-mt' id="bool">bool: {{ bool }}</text>
			<text class='uni-common-mt' id="count">count: {{count}}</text>
			<button class='uni-common-mt' id="increment-btn" @click="increment">increment</button>
			<text class='uni-common-mt' id="obj-str">obj.str: {{ obj['str'] }}</text>
			<text class='uni-common-mt' id="obj-num">obj.num: {{ obj['num'] }}</text>
			<text class='uni-common-mt' id="obj-bool">obj.bool: {{ obj['bool'] }}</text>
			<button class='uni-common-mt' id="update-obj-btn" @click="updateObj">update obj</button>
			<RenderFunction :str='str' :count='count' :obj='obj' @compUpdateObj='compUpdateObj' :isShow='true' />
			<Foo>
				<text class="uni-common-mt" id="default-slot-in-foo">default slot in Foo</text>
			</Foo>
		</view>
	<!-- #ifdef APP -->
	</scroll-view>
	<!-- #endif -->
</template>

<script>
	import RenderFunction from './RenderFunction.uvue'
	import Foo from './Foo.uvue'
	export default {
		components: {
			RenderFunction,
			Foo
		},
		setup() {
			const count = ref(0)
			// 函数只能通过声明变量,赋值函数的方式,不支持 function xxx(){}
			const increment = () => { count.value++ }
			const obj = reactive({
				str: 'obj default str',
				num: 0,
				bool: false,
			})
			const updateObj = () => {
				obj['str'] = 'obj new str'
				obj['num'] = 100
				obj['bool'] = true
			}
			const compUpdateObj = () => {
				obj['str'] = 'obj new str by comp update'
				obj['num'] = 200
				obj['bool'] = true
			}
			return {
				str: 'default str',
				num: 0,
				bool: false,
				count,
				increment,
				obj,
				updateObj,
				compUpdateObj
			}
		}
	}
</script>