Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
362316f0
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
398
Star
3
Fork
10
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello-uvue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
You need to sign in or sign up before continuing.
提交
362316f0
编写于
1月 20, 2025
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(v-on): 补充 prevent 修饰符示例及测试
上级
b78bbcbd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
8 deletion
+58
-8
pages/directive/v-on/v-on-composition.uvue
pages/directive/v-on/v-on-composition.uvue
+26
-4
pages/directive/v-on/v-on-options.uvue
pages/directive/v-on/v-on-options.uvue
+20
-4
pages/directive/v-on/v-on.test.js
pages/directive/v-on/v-on.test.js
+12
-0
未找到文件。
pages/directive/v-on/v-on-composition.uvue
浏览文件 @
362316f0
...
...
@@ -17,14 +17,14 @@
<button class="mb-10 btn" v-on:click="handleClick($event as MouseEvent)">
v-on:click="handleClick($event as MouseEvent)"
内联声明,注意要显式声明$event的类型
</button>
</button>
<!-- #ifndef MP -->
<button class="mb-10 btn" v-on:[event]="handleClick">
v-on:[event]="handleClick" 动态事件
</button>
<button class="mb-10 btn" v-on="{ click: handleClick }">
v-on="{ click: handleClick }" 对象语法
</button>
</button>
<!-- #endif -->
<!-- TODO: ios 不支持 -->
<!-- #ifndef APP-IOS || MP -->
...
...
@@ -33,16 +33,38 @@
<view @click="handleClick">
<button class="mb-10 btn" id="btn-stop" @click.stop="handleClick">@click stop</button>
</view>
<button class="mb-10" id="btn-prevent" @touchstart.prevent="handleTouchstart" @click="handleClick">@touch prevent</button>
</view>
</template>
<script setup lang="uts">
const count = ref(0)
const event = ref('click')
const event = ref('click')
type BtnPreventRect = {
value: DOMRect | null
}
let btnPreventRect = reactive({
value: null
} as BtnPreventRect)
onReady(() => {
const btnPrevent = uni.getElementById("btn-prevent")
btnPreventRect.value = btnPrevent!.getBoundingClientRect()
btnPreventRect.value!.y += uni.getSystemInfoSync().safeArea.top + 44
})
const handleTouchstart = () => {
console.log('handleTouchstart')
}
const handleClick = (e : MouseEvent) => {
count.value++
console.log('handleClick', e)
}
}
defineExpose({
btnPreventRect
})
</script>
pages/directive/v-on/v-on-options.uvue
浏览文件 @
362316f0
...
...
@@ -15,14 +15,14 @@
<button class="mb-10 btn" v-on:click="handleClick($event as MouseEvent)">
v-on:click="handleClick($event as MouseEvent)"
内联声明,注意要显式声明$event的类型
</button>
</button>
<!-- #ifndef MP -->
<button class="mb-10 btn" v-on:[event]="handleClick">
v-on:[event]="handleClick" 动态事件
</button>
<button class="mb-10 btn" v-on="{ click: handleClick }">
v-on="{ click: handleClick }" 对象语法
</button>
</button>
<!-- #endif -->
<!-- TODO: ios 不支持 -->
<!-- #ifndef APP-IOS || MP -->
...
...
@@ -31,18 +31,34 @@
<view @click="handleClick">
<button class="mb-10 btn" id="btn-stop" @click.stop="handleClick">@click stop</button>
</view>
<button class="mb-10" id="btn-prevent" @touchstart.prevent="handleTouchstart" @click="handleClick">@touch prevent</button>
</view>
</template>
<script lang="uts">
<script lang="uts">
type BtnPreventRect = {
value: DOMRect | null
}
export default {
data() {
return {
count: 0,
event: 'click'
event: 'click',
btnPreventRect: {
value: null as DOMRect | null
} as BtnPreventRect
}
},
onReady(){
const btnPrevent = uni.getElementById("btn-prevent")
this.btnPreventRect.value = btnPrevent?.getBoundingClientRect()
this.btnPreventRect.value!.y += uni.getSystemInfoSync().safeArea.top + 44
},
methods: {
handleTouchstart(){
console.log('handleTouchstart')
},
handleClick(e : MouseEvent) {
this.count++
console.log('handleClick', e)
...
...
pages/directive/v-on/v-on.test.js
浏览文件 @
362316f0
...
...
@@ -3,6 +3,7 @@ const COMPOSITION_PAGE_PATH = '/pages/directive/v-on/v-on-composition'
describe
(
'
v-on
'
,
()
=>
{
const
platformInfo
=
process
.
env
.
uniTestPlatformInfo
.
toLowerCase
()
const
isAndroid
=
platformInfo
.
startsWith
(
'
android
'
)
const
isIOS
=
platformInfo
.
startsWith
(
'
ios
'
)
const
isMP
=
platformInfo
.
startsWith
(
'
mp
'
)
let
page
...
...
@@ -29,6 +30,17 @@ describe('v-on', () => {
await
onceBtn
.
tap
()
expect
(
await
count
.
text
()).
toBe
(
supportedCount
)
}
if
(
isAndroid
||
isIOS
)
{
const
btnPreventRect
=
(
await
page
.
data
(
'
btnPreventRect
'
)).
value
const
x
=
Math
.
ceil
(
btnPreventRect
.
x
+
btnPreventRect
.
width
/
2
)
const
y
=
Math
.
ceil
(
btnPreventRect
.
y
+
btnPreventRect
.
height
/
2.0
)
await
program
.
tap
({
x
:
x
,
y
:
y
,
duration
:
100
})
expect
(
await
count
.
text
()).
toBe
(
supportedCount
)
}
}
it
(
'
v-on options API
'
,
async
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录