Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
1a99a547
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6388
Star
110
Fork
186
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
24
列表
看板
标记
里程碑
合并请求
2
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
24
Issue
24
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1a99a547
编写于
10月 12, 2024
作者:
shutao-dc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
native-button.uvue改为组合式 API
上级
144d0b0b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
46 deletion
+46
-46
pages/component/native-view/native-view.uvue
pages/component/native-view/native-view.uvue
+4
-1
uni_modules/native-button/components/native-button/native-button.uvue
...native-button/components/native-button/native-button.uvue
+42
-45
未找到文件。
pages/component/native-view/native-view.uvue
浏览文件 @
1a99a547
...
@@ -12,7 +12,8 @@
...
@@ -12,7 +12,8 @@
return {
return {
title: 'Hello',
title: 'Hello',
buttonText: "native-button",
buttonText: "native-button",
isLoad: false
isLoad: false,
clickCount: 0
}
}
},
},
onLoad() {
onLoad() {
...
@@ -23,6 +24,8 @@
...
@@ -23,6 +24,8 @@
uni.showToast({
uni.showToast({
title: "按钮被点击了"
title: "按钮被点击了"
})
})
this.clickCount ++
this.buttonText = "native-button"+this.clickCount
},
},
onload() {
onload() {
//标记已初始化 用于自动化测试
//标记已初始化 用于自动化测试
...
...
uni_modules/native-button/components/native-button/native-button.uvue
浏览文件 @
1a99a547
<template>
<template>
<native-view @init="onviewinit" @customClick="ontap"></native-view>
<native-view @init="onviewinit" @customClick="ontap"></native-view>
</template>
</template>
<script lang="uts">
<script
setup
lang="uts">
import { NativeButton } from "@/uni_modules/native-button";
import { NativeButton } from "@/uni_modules/native-button";
export default {
let button : NativeButton | null = null
data() {
return {
//声明属性
button: null as NativeButton | null,
const props = defineProps<{ text : string }>()
value: ""
}
//声明事件
},
const emit = defineEmits<{
props: {
(e : "load") : void
"text": {
(e : "buttonTap", event : UniNativeViewEvent) : void
type: String,
}>()
default: ''
}
//声明方法
},
function updateText(value : string) {
watch: {
button?.updateText(value)
"text": {
}
handler(newValue : string, oldValue : string) {
this.value = newValue
//监听属性变化
this.updateText(newValue)
watchEffect(() => {
},
// console.log("watchEffect "+props.text)
immediate: true
const text = props.text
},
updateText(text)
},
})
methods: {
//native-view初始化时触发此方法
//native-view初始化时触发此方法
onviewinit(e : UniNativeViewInitEvent) {
function onviewinit(e : UniNativeViewInitEvent) {
//获取UniNativeViewElement 传递给NativeButton对象
//获取UniNativeViewElement 传递给NativeButton对象
this.button = new NativeButton(e.detail.element);
button = new NativeButton(e.detail.element);
this.button?.updateText(this.value)
updateText(props.text)
this.$emit("load")
emit("load")
},
}
ontap(e: UniNativeViewEvent) {
this.$emit("buttonTap", e)
function ontap(e : UniNativeViewEvent) {
},
emit("buttonTap", e)
updateText(value: string) {
}
this.button?.updateText(value)
}
function onUnmounted() {
},
// iOS平台需要主动释放 uts 实例
unmounted() {
button?.destroy()
// iOS平台需要主动释放 uts 实例
}
this.button?.destroy()
}
}
</script>
</script>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录