提交 5a19f513 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

refactor(directive): v-once

上级 cee5edba
...@@ -201,6 +201,20 @@ ...@@ -201,6 +201,20 @@
"navigationBarTitleText": "v-pre" "navigationBarTitleText": "v-pre"
} }
}, },
// #ifdef APP
{
"path": "pages/directive/v-once/v-once-options",
"style": {
"navigationBarTitleText": "v-once 选项式 API"
}
},
{
"path": "pages/directive/v-once/v-once-composition",
"style": {
"navigationBarTitleText": "v-once 组合式 API"
}
},
// #endif
{ {
...@@ -265,14 +279,6 @@ ...@@ -265,14 +279,6 @@
"navigationBarTitleText": "v-model" "navigationBarTitleText": "v-model"
} }
}, },
// #ifdef APP
{
"path": "pages/directive/v-once/v-once",
"style": {
"navigationBarTitleText": "v-once"
}
},
// #endif
{ {
"path": "pages/directive/v-memo/v-memo", "path": "pages/directive/v-memo/v-memo",
"style": { "style": {
......
<template>
<view class="page">
<view class="flex flex-row justify-between mb-10" v-once>
<text>This msg will never change:</text>
<text id='v-once-msg'>{{ msg }}</text>
</view>
<view class="flex flex-row justify-between mb-10">
<text>msg:</text>
<text id="msg">{{ msg }}</text>
</view>
<button id="btn" class="mb-10" type="primary" @click="changeMessage">
change message
</button>
</view>
</template>
<script setup lang="uts">
const msg = ref('hello world')
const changeMessage = () => {
msg.value = 'msg changed'
}
</script>
<template> <template>
<view class="page"> <view class="page">
<view class="split-title">v-once</view> <view class="flex flex-row justify-between mb-10" v-once>
<text class="uni-common-mt v-once-text" v-once>This will never change: {{ msg }}</text> <text>This msg will never change:</text>
<text class="uni-common-mt">msg: {{msg}}</text> <text id='v-once-msg'>{{ msg }}</text>
<button class="uni-common-mt btn" type="primary" @click="changeMessage">change message</button> </view>
<view class="flex flex-row justify-between mb-10">
<text>msg:</text>
<text id="msg">{{ msg }}</text>
</view>
<button id="btn" class="mb-10" type="primary" @click="changeMessage">
change message
</button>
</view> </view>
</template> </template>
......
const PAGE_PATH = '/pages/directive/v-once/v-once' const OPTIONS_PAGE_PATH = '/pages/directive/v-once/v-once-options'
const COMPOSITION_PAGE_PATH = '/pages/directive/v-once/v-once-composition'
describe('v-once', () => { describe('v-once', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) { if (process.env.uniTestPlatformInfo.startsWith('web')) {
...@@ -9,22 +10,29 @@ describe('v-once', () => { ...@@ -9,22 +10,29 @@ describe('v-once', () => {
return return
} }
let page let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) const test = async (pagePath) => {
page = await program.reLaunch(pagePath)
await page.waitFor('view') await page.waitFor('view')
})
it('basic', async () => { const vOnceMsg = await page.$('#v-once-msg')
const vOnceTextEl = await page.$('.v-once-text') expect(await vOnceMsg.text()).toBe('hello world')
let vOnceTextText = await vOnceTextEl.text()
expect(vOnceTextText).toBe('This will never change: hello world') const msg = await page.$('#msg')
expect(await msg.text()).toBe('hello world')
const btn = await page.$('.btn') const btn = await page.$('#btn')
await btn.tap() await btn.tap()
const msg = await page.data('msg') expect(await vOnceMsg.text()).toBe('hello world')
expect(msg).toBe('msg changed') expect(await msg.text()).toBe('msg changed')
}
vOnceTextText = await vOnceTextEl.text()
expect(vOnceTextText).toBe('This will never change: hello world') it('v-once options API', async () => {
await test(OPTIONS_PAGE_PATH)
})
it('v-once composition API', async () => {
await test(COMPOSITION_PAGE_PATH)
}) })
}) })
\ No newline at end of file
...@@ -719,7 +719,25 @@ export default { ...@@ -719,7 +719,25 @@ export default {
id: 'v-pre', id: 'v-pre',
name: 'v-pre', name: 'v-pre',
url: 'v-pre/v-pre' url: 'v-pre/v-pre'
} },
// #ifdef APP
{
id: 'v-once',
name: 'v-once',
children: [
{
id: 'v-once-options',
name: 'v-once 选项式 API',
url: 'v-once-options'
},
{
id: 'v-once-composition',
name: 'v-once 组合式 API',
url: 'v-once-composition'
},
]
},
// #endif
] ]
}, },
{ {
......
...@@ -161,11 +161,11 @@ function transform(fileInfo, api) { ...@@ -161,11 +161,11 @@ function transform(fileInfo, api) {
- [ ] v-bind - [ ] v-bind
- [ ] v-model - [ ] v-model
- [ ] v-slot - [ ] v-slot
- [ ] v-pre - [x] v-pre
- [ ] v-once - [x] v-once
- [ ] v-memo - [ ] v-memo
- [ ] v-text - [ ] v-text
- [ ] -cloak - [ ] v-cloak 暂不支持
## lifecycle ## lifecycle
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册