提交 96fcff23 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

refactor(directive): v-for add map and set

上级 c4b89419
...@@ -18,7 +18,10 @@ ...@@ -18,7 +18,10 @@
</view> </view>
<view class="bold mb-10">v-for & v-if list items</view> <view class="bold mb-10">v-for & v-if list items</view>
<view id="v-for-v-if-list-items" v-for="item in listItems" :key="item.name"> <view
id="v-for-v-if-list-items"
v-for="item in listItems"
:key="item.name">
<template v-if="item.show"> <template v-if="item.show">
<view class="mb-10 flex justify-between flex-row"> <view class="mb-10 flex justify-between flex-row">
<text :id="item.name">{{ item.name }}</text> <text :id="item.name">{{ item.name }}</text>
...@@ -63,6 +66,18 @@ ...@@ -63,6 +66,18 @@
}}</text> }}</text>
</view> </view>
</view> </view>
<view
class="mb-10 flex justify-between flex-row"
v-for="item in mapList"
:key="item[0]">
<text>{{ item[0] }}</text>
<text :id="item[0]">{{ item[1] }}</text>
</view>
<view class="mb-10" v-for="(item, index) in setList" :key="index">
<text :id="`set-value-${index + 1}`">{{ item }}</text>
</view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -111,4 +126,12 @@ const listItems = ref([ ...@@ -111,4 +126,12 @@ const listItems = ref([
] ]
}, },
] as ListItem[]) ] as ListItem[])
const mapList = new Map<string, string>([
['map-key-1', 'map value 1'],
['map-key-2', 'map value 2'],
['map-key-3', 'map value 3'],
])
const setList = new Set<string>(['set value 1', 'set value 2', 'set value 3'])
</script> </script>
...@@ -66,6 +66,18 @@ ...@@ -66,6 +66,18 @@
}}</text> }}</text>
</view> </view>
</view> </view>
<view
class="mb-10 flex justify-between flex-row"
v-for="item in mapList"
:key="item[0]">
<text>{{ item[0] }}</text>
<text :id="item[0]">{{ item[1] }}</text>
</view>
<view class="mb-10" v-for="(item, index) in setList" :key="index">
<text :id="`set-value-${index + 1}`">{{ item }}</text>
</view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -86,6 +98,7 @@ type ListItem = { ...@@ -86,6 +98,7 @@ type ListItem = {
items?: ListItem[] items?: ListItem[]
} }
// TODO: v-for map set deep array 动态增加删除
export default { export default {
data() { data() {
return { return {
...@@ -116,6 +129,12 @@ export default { ...@@ -116,6 +129,12 @@ export default {
] ]
}, },
] as ListItem[], ] as ListItem[],
mapList: new Map<string, string>([
['map-key-1', 'map value 1'],
['map-key-2', 'map value 2'],
['map-key-3', 'map value 3'],
]),
setList: new Set<string>(['set value 1', 'set value 2', 'set value 3']),
} }
} }
} }
......
...@@ -33,6 +33,20 @@ describe('v-for', () => { ...@@ -33,6 +33,20 @@ describe('v-for', () => {
await vShow1Count.tap() await vShow1Count.tap()
expect(await vShow1Count.text()).toBe('2') expect(await vShow1Count.text()).toBe('2')
const mapValue1 = await page.$('#map-key-1')
expect(await mapValue1.text()).toBe('map value 1')
const mapValue2 = await page.$('#map-key-2')
expect(await mapValue2.text()).toBe('map value 2')
const mapValue3 = await page.$('#map-key-3')
expect(await mapValue3.text()).toBe('map value 3')
const setValue1 = await page.$('#set-value-1')
expect(await setValue1.text()).toBe('set value 1')
const setValue2 = await page.$('#set-value-2')
expect(await setValue2.text()).toBe('set value 2')
const setValue3 = await page.$('#set-value-3')
expect(await setValue3.text()).toBe('set value 3')
await page.waitFor(500) await page.waitFor(500)
const image = await program.screenshot({ const image = await program.screenshot({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册