From 07972eaa0f744d2fa915f0988af58ab21c264e8a Mon Sep 17 00:00:00 2001
From: zhenyuWang <13641039885@163.com>
Date: Tue, 23 Apr 2024 17:57:54 +0800
Subject: [PATCH] refactor(directive): v-on
---
pages.json | 19 +++++---
pages/directive/v-on/v-on-composition.uvue | 41 +++++++++++++++++
pages/directive/v-on/v-on-options.uvue | 45 +++++++++++++++++++
pages/directive/v-on/v-on.test.js | 36 +++++++++------
pages/directive/v-on/v-on.uvue | 42 -----------------
pages/index/index.uvue | 16 +++++++
...ions-API-composition-API-correspondence.md | 2 +-
7 files changed, 139 insertions(+), 62 deletions(-)
create mode 100644 pages/directive/v-on/v-on-composition.uvue
create mode 100644 pages/directive/v-on/v-on-options.uvue
delete mode 100644 pages/directive/v-on/v-on.uvue
diff --git a/pages.json b/pages.json
index 0b25dc5..4a52aa8 100644
--- a/pages.json
+++ b/pages.json
@@ -183,6 +183,19 @@
"navigationBarTitleText": "v-for 组合式 API"
}
},
+ {
+ "path": "pages/directive/v-on/v-on-options",
+ "style": {
+ "navigationBarTitleText": "v-on 选项式 API"
+ }
+ },
+ {
+ "path": "pages/directive/v-on/v-on-composition",
+ "style": {
+ "navigationBarTitleText": "v-on 组合式 API"
+ }
+ },
+
{
"path": "pages/directive/v-bind/v-bind",
@@ -246,12 +259,6 @@
"navigationBarTitleText": "v-model"
}
},
- {
- "path": "pages/directive/v-on/v-on",
- "style": {
- "navigationBarTitleText": "v-on"
- }
- },
// #ifdef APP
{
"path": "pages/directive/v-once/v-once",
diff --git a/pages/directive/v-on/v-on-composition.uvue b/pages/directive/v-on/v-on-composition.uvue
new file mode 100644
index 0000000..bea027c
--- /dev/null
+++ b/pages/directive/v-on/v-on-composition.uvue
@@ -0,0 +1,41 @@
+
+
+ 下方按钮点击累加 count
+
+ count:
+ {{ count }}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pages/directive/v-on/v-on-options.uvue b/pages/directive/v-on/v-on-options.uvue
new file mode 100644
index 0000000..0909514
--- /dev/null
+++ b/pages/directive/v-on/v-on-options.uvue
@@ -0,0 +1,45 @@
+
+
+ 下方按钮点击累加 count
+
+ count:
+ {{ count }}
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pages/directive/v-on/v-on.test.js b/pages/directive/v-on/v-on.test.js
index df97550..63ab735 100644
--- a/pages/directive/v-on/v-on.test.js
+++ b/pages/directive/v-on/v-on.test.js
@@ -1,19 +1,29 @@
-const PAGE_PATH = '/pages/directive/v-on/v-on'
+const OPTIONS_PAGE_PATH = '/pages/directive/v-on/v-on-options'
+const COMPOSITION_PAGE_PATH = '/pages/directive/v-on/v-on-composition'
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()
+
+ const test = async (pagePath) => {
+ page = await program.reLaunch(pagePath)
+ await page.waitFor('view')
+
+ const count = await page.$('#count')
+ expect(await count.text()).toBe('0')
+
+ const btnList = await page.$$('.btn')
+ for (let i = 0; i < btnList.length; i++) {
+ await btnList[i].tap()
}
- expect(await countText.text()).toBe(expectedCount + '')
- expect((await page.data()).count).toBe(expectedCount)
+
+ expect(await count.text()).toBe('6')
+ }
+
+ it('v-on options API', async () => {
+ await test(OPTIONS_PAGE_PATH)
+ })
+
+ it('v-on composition API', async () => {
+ await test(COMPOSITION_PAGE_PATH)
})
})
\ No newline at end of file
diff --git a/pages/directive/v-on/v-on.uvue b/pages/directive/v-on/v-on.uvue
deleted file mode 100644
index 9132c9d..0000000
--- a/pages/directive/v-on/v-on.uvue
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
- v-on
- @click="onClick" 缩写
- v-on:click="onClick" 方法处理函数
- v-on:click="count++" 内联事件
- v-on:click="onClick($event as
- MouseEvent)" 内联声明,注意要显示声明$event的类型
- v-on:[event]="onClick" 动态事件
-
-
- v-on="{ click: onClick }" 对象语法
-
- {{count}}
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pages/index/index.uvue b/pages/index/index.uvue
index c1c9225..e5734ab 100644
--- a/pages/index/index.uvue
+++ b/pages/index/index.uvue
@@ -698,6 +698,22 @@ export default {
url: 'v-for-composition'
},
]
+ },
+ {
+ id: 'v-on',
+ name: 'v-on',
+ children: [
+ {
+ id: 'v-on-options',
+ name: 'v-on 选项式 API',
+ url: 'v-on-options'
+ },
+ {
+ id: 'v-on-composition',
+ name: 'v-on 组合式 API',
+ url: 'v-on-composition'
+ },
+ ]
}
]
},
diff --git a/refactor_options-API-composition-API-correspondence.md b/refactor_options-API-composition-API-correspondence.md
index 1c622f6..968b72e 100644
--- a/refactor_options-API-composition-API-correspondence.md
+++ b/refactor_options-API-composition-API-correspondence.md
@@ -157,7 +157,7 @@ function transform(fileInfo, api) {
- [x] v-show
- [x] v-if v-else-if v-else
- [x] v-for
-- [ ] v-on
+- [x] v-on
- [ ] v-bind
- [ ] v-model
- [ ] v-slot
--
GitLab