提交 1a197182 编写于 作者: shutao-dc's avatar shutao-dc

调整native-view示例组件命名

# Conflicts:
#	pages/component/native-view/native-view.uvue
#	uni_modules/native-button/components/native-button/native-button.uvue
上级 4a39ae6e
......@@ -2,7 +2,7 @@
<view>
<native-button class="native-button" style="width: 200px; height: 100px;" :text="buttonText" @buttonTap="ontap"
@load="onload"></native-button>
<time-picker class="native-time-picker" :hour=2 :minute=3 @changed="onChanged"></time-picker>
<native-time-picker class="native-time-picker" :hour=2 :minute=3 @changed="onChanged"></native-time-picker>
</view>
</template>
......@@ -12,7 +12,8 @@
return {
title: 'Hello',
buttonText: "native-button",
isLoad: false
isLoad: false,
clickCount: 0
}
},
onLoad() {
......@@ -23,6 +24,8 @@
uni.showToast({
title: "按钮被点击了"
})
this.clickCount ++
this.buttonText = "native-button"+this.clickCount
},
onload() {
//标记已初始化 用于自动化测试
......
<template>
<native-view @init="onviewinit" @customClick="ontap"></native-view>
</template>
<script lang="uts">
<script setup lang="uts">
import { NativeButton } from "@/uni_modules/native-button";
export default {
data() {
return {
button: null as NativeButton | null,
value: ""
let button : NativeButton | null = null
//声明属性
const props = defineProps<{ text : string }>()
//声明事件
const emit = defineEmits<{
(e : "load") : void
(e : "buttonTap", event : UniNativeViewEvent) : void
}>()
//声明方法
function updateText(value : string) {
button?.updateText(value)
}
},
props: {
"text": {
type: String,
default: ''
}
},
watch: {
"text": {
handler(newValue : string, oldValue : string) {
this.value = newValue
this.updateText(newValue)
},
immediate: true
},
},
methods: {
//监听属性变化
watchEffect(() => {
const text = props.text
updateText(text)
})
//native-view初始化时触发此方法
onviewinit(e : UniNativeViewInitEvent) {
function onviewinit(e : UniNativeViewInitEvent) {
//获取UniNativeViewElement 传递给NativeButton对象
this.button = new NativeButton(e.detail.element);
this.button?.updateText(this.value)
this.$emit("load")
},
ontap(e: UniNativeViewEvent) {
this.$emit("buttonTap", e)
},
updateText(value: string) {
this.button?.updateText(value)
button = new NativeButton(e.detail.element);
updateText(props.text)
emit("load")
}
},
unmounted() {
// iOS平台需要主动释放 uts 实例
this.button?.destroy()
function ontap(e : UniNativeViewEvent) {
emit("buttonTap", e)
}
function onUnmounted() {
// iOS平台需要主动释放 uts 实例
button?.destroy()
}
</script>
{
"id": "uni-native-button",
"displayName": "uni-native-button",
"id": "native-button",
"displayName": "native-button",
"version": "0.0.1",
"description": "vue开发button原生组件",
"keywords": [
"tencent",
"map",
"tmap"
],
"repository": "",
"engines": {
"HBuilderX": "^4.25"
......
{
"id": "uni-time-picker",
"displayName": "uni-time-picker",
"id": "native-time-picker",
"displayName": "native-time-picker",
"version": "1.0.0",
"description": "uni-time-picker",
"keywords": [
"uni-time-picker"
],
"description": "native-time-picker",
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
......
# uni-time-picker
\ No newline at end of file
# native-time-picker
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册