native-button.uvue 1006 字节
Newer Older
shutao-dc's avatar
shutao-dc 已提交
1 2
<template>

3
	<object @init="onObjectInit" @customClick="onclick"></object>
shutao-dc's avatar
shutao-dc 已提交
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

</template>

<script lang="uts">

  import { NativeButton } from "@/uni_modules/uni-native-button";


	export default {

		data() {
			return {
				button: null as NativeButton | null,
				value : ""
			}
		},
		props: {
			"text": {
				type: String,
				default: ''
			}
		},
		watch: {
			"text": {
				handler(newValue : string, oldValue : string) {
					this.value = newValue
					this.button?.updateText(this.value)
				},
				immediate: true
			},
		},
		methods: {
			onObjectInit(e : UniObjectInitEvent) {
				this.button = new NativeButton(e.detail.element);
				this.button?.updateText(this.value)
shutao-dc's avatar
shutao-dc 已提交
39
				this.$emit("load")
shutao-dc's avatar
shutao-dc 已提交
40 41
			},
			onclick(e: UniObjectCustomEvent) {
42
				this.$emit("buttonTap", e)
shutao-dc's avatar
shutao-dc 已提交
43 44 45
			}
		},
		unmounted() {
46 47 48
      // #ifdef APP-IOS
      // iOS平台需要主动释放 uts 实例
      this.button.destroy()
49
      // #endif
shutao-dc's avatar
shutao-dc 已提交
50 51 52 53 54 55 56
		}
	}
</script>

<style>

</style>