Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello-uvue
提交
2a664515
H
hello-uvue
项目概览
DCloud
/
hello-uvue
通知
347
Star
2
Fork
7
代码
文件
提交
分支
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看板
提交
2a664515
编写于
9月 05, 2023
作者:
Y
yurj26
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: v-on
上级
f4551df2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
56 deletion
+59
-56
pages/directive/v-on/v-on.test.js
pages/directive/v-on/v-on.test.js
+18
-23
pages/directive/v-on/v-on.uvue
pages/directive/v-on/v-on.uvue
+41
-33
未找到文件。
pages/directive/v-on/v-on.test.js
浏览文件 @
2a664515
const
PAGE_PATH
=
'
/pages/directive/v-on/v-on
'
describe
(
'
v-on
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
view:click
'
,
async
()
=>
{
let
count
=
0
const
countText
=
await
page
.
$
(
'
.count
'
)
const
view
=
await
page
.
$
(
'
.view-click
'
)
await
view
.
tap
()
count
+=
1
expect
(
await
countText
.
text
()).
toBe
(
count
+
''
)
const
view_v_on
=
await
page
.
$
(
'
.view-v-on-click
'
)
await
view_v_on
.
tap
()
count
+=
1
expect
(
await
countText
.
text
()).
toBe
(
count
+
''
)
})
const
PAGE_PATH
=
'
/pages/directive/v-on/v-on
'
describe
(
'
v-on
'
,
()
=>
{
let
page
beforeAll
(
async
()
=>
{
page
=
await
program
.
reLaunch
(
PAGE_PATH
)
await
page
.
waitFor
(
500
)
})
it
(
'
view:click
'
,
async
()
=>
{
const
expectedCount
=
6
const
countText
=
await
page
.
$
(
'
.count
'
)
const
clickEls
=
await
page
.
$$
(
'
.view-click
'
)
for
(
let
i
=
0
;
i
<
clickEls
.
length
;
i
++
)
{
await
clickEls
[
i
].
tap
()
}
expect
(
await
countText
.
text
()).
toBe
(
expectedCount
+
''
)
expect
((
await
page
.
data
()).
count
).
toBe
(
expectedCount
)
})
})
\ No newline at end of file
pages/directive/v-on/v-on.uvue
浏览文件 @
2a664515
<template>
<view class="page">
<view class="split-title">v-on</view>
<view class="button view-click" @click="onClick">click</view>
<view class="button view-v-on-click" v-on:click="onClick">v-on:click</view>
<view>
<text class="count">{{count}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
count: 0
}
},
methods: {
onClick() {
this.count++
console.log('onClick')
}
}
}
</script>
<style>
.button {
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
}
<template>
<view class="page">
<view class="split-title">v-on</view>
<view class="view-click" @click="onClick">@click="onClick" 缩写</view>
<view class="view-click" v-on:click="onClick">v-on:click="onClick" 方法处理函数</view>
<view class="view-click" v-on:click="count++">v-on:click="count++" 内联事件</view>
<view class="view-click" v-on:click="onClick($event as MouseEvent)">v-on:click="onClick($event as
MouseEvent)" 内联声明,注意要显示声明$event的类型</view>
<view class="view-click" v-on:[event]="onClick">v-on:[event]="onClick" 动态事件</view>
<!-- TODO 不支持修饰符 -->
<!-- <view class="view-click" v-on:click.once="onClick">v-on:click.once="onClick" 点击事件将最多触发一次</view> -->
<view class="view-click" v-on="{ click: onClick }">v-on="{ click: onClick }" 对象语法</view>
<view>
<text class="count">{{count}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
count: 0,
event: 'click'
}
},
methods: {
onClick(e : MouseEvent) {
this.count++
console.log('onClick', e)
}
}
}
</script>
<style>
.view-click {
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
}
</style>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录