提交 2a664515 编写于 作者: Y yurj26

feat: v-on

上级 f4551df2
const PAGE_PATH = '/pages/directive/v-on/v-on' const PAGE_PATH = '/pages/directive/v-on/v-on'
describe('v-on', () => { describe('v-on', () => {
let page let page
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500) await page.waitFor(500)
}) })
it('view:click', async () => { it('view:click', async () => {
let count = 0 const expectedCount = 6
const countText = await page.$('.count')
const countText = await page.$('.count') const clickEls = await page.$$('.view-click')
for (let i = 0; i < clickEls.length; i++) {
const view = await page.$('.view-click') await clickEls[i].tap()
await view.tap() }
count += 1 expect(await countText.text()).toBe(expectedCount + '')
expect(await countText.text()).toBe(count + '') expect((await page.data()).count).toBe(expectedCount)
})
const view_v_on = await page.$('.view-v-on-click')
await view_v_on.tap()
count += 1
expect(await countText.text()).toBe(count + '')
})
}) })
\ No newline at end of file
<template> <template>
<view class="page"> <view class="page">
<view class="split-title">v-on</view> <view class="split-title">v-on</view>
<view class="button view-click" @click="onClick">click</view> <view class="view-click" @click="onClick">@click="onClick" 缩写</view>
<view class="button view-v-on-click" v-on:click="onClick">v-on:click</view> <view class="view-click" v-on:click="onClick">v-on:click="onClick" 方法处理函数</view>
<view> <view class="view-click" v-on:click="count++">v-on:click="count++" 内联事件</view>
<text class="count">{{count}}</text> <view class="view-click" v-on:click="onClick($event as MouseEvent)">v-on:click="onClick($event as
</view> MouseEvent)" 内联声明,注意要显示声明$event的类型</view>
</view> <view class="view-click" v-on:[event]="onClick">v-on:[event]="onClick" 动态事件</view>
</template> <!-- TODO 不支持修饰符 -->
<!-- <view class="view-click" v-on:click.once="onClick">v-on:click.once="onClick" 点击事件将最多触发一次</view> -->
<script> <view class="view-click" v-on="{ click: onClick }">v-on="{ click: onClick }" 对象语法</view>
export default { <view>
data() { <text class="count">{{count}}</text>
return { </view>
count: 0 </view>
} </template>
},
methods: { <script>
onClick() { export default {
this.count++ data() {
console.log('onClick') return {
} count: 0,
} event: 'click'
} }
</script> },
methods: {
<style> onClick(e : MouseEvent) {
.button { this.count++
margin-bottom: 10px; console.log('onClick', e)
padding: 10px; }
border: 1px solid #ccc; }
} }
</script>
<style>
.view-click {
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
}
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册