提交 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
<template>
<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>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello',
buttonText: "native-button",
isLoad: false
}
},
onLoad() {
},
methods: {
ontap(e : UniNativeViewEvent) {
uni.showToast({
title: "按钮被点击了"
})
},
onload() {
//标记已初始化 用于自动化测试
this.isLoad = true
},
onChanged(e : UniNativeViewEvent) {
console.log("onchanged-----", e.detail)
}
}
}
</script>
<style>
.native-button {
height: 100px;
width: 100px;
margin: 25px auto 25px auto;
}
.native-time-picker {
margin: 10px auto 25px auto;
border-style: solid;
border-radius: 5px;
}
<template>
<view>
<native-button class="native-button" style="width: 200px; height: 100px;" :text="buttonText" @buttonTap="ontap"
@load="onload"></native-button>
<native-time-picker class="native-time-picker" :hour=2 :minute=3 @changed="onChanged"></native-time-picker>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello',
buttonText: "native-button",
isLoad: false,
clickCount: 0
}
},
onLoad() {
},
methods: {
ontap(e : UniNativeViewEvent) {
uni.showToast({
title: "按钮被点击了"
})
this.clickCount ++
this.buttonText = "native-button"+this.clickCount
},
onload() {
//标记已初始化 用于自动化测试
this.isLoad = true
},
onChanged(e : UniNativeViewEvent) {
console.log("onchanged-----", e.detail)
}
}
}
</script>
<style>
.native-button {
height: 100px;
width: 100px;
margin: 25px auto 25px auto;
}
.native-time-picker {
margin: 10px auto 25px auto;
border-style: solid;
border-radius: 5px;
}
</style>
<template>
<native-view @init="onviewinit" @customClick="ontap"></native-view>
</template>
<script lang="uts">
<native-view @init="onviewinit" @customClick="ontap"></native-view>
</template>
<script setup lang="uts">
import { NativeButton } from "@/uni_modules/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.updateText(newValue)
},
immediate: true
},
},
methods: {
//native-view初始化时触发此方法
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)
}
},
unmounted() {
// iOS平台需要主动释放 uts 实例
this.button?.destroy()
}
}
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)
}
//监听属性变化
watchEffect(() => {
const text = props.text
updateText(text)
})
//native-view初始化时触发此方法
function onviewinit(e : UniNativeViewInitEvent) {
//获取UniNativeViewElement 传递给NativeButton对象
button = new NativeButton(e.detail.element);
updateText(props.text)
emit("load")
}
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"
......@@ -80,4 +77,4 @@
}
}
}
}
\ No newline at end of file
}
# 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.
先完成此消息的编辑!
想要评论请 注册