提交 34485147 编写于 作者: F fxy060608

feat(v-bind): 补充v-bind="obj"各种测试例

上级 54314d03
<template> <template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="page"> <view class="page">
<!-- v-bind attribute --> <!-- v-bind attribute -->
<button id="disabled-btn" class="mb-10" :disabled="true"> <button id="disabled-btn" class="mb-10" :disabled="true">
...@@ -25,13 +28,27 @@ ...@@ -25,13 +28,27 @@
<Foo :title="dataInfo.fooProps.title" :num="dataInfo.fooProps.num" :obj="dataInfo.fooProps.obj" /> <Foo :title="dataInfo.fooProps.title" :num="dataInfo.fooProps.num" :obj="dataInfo.fooProps.obj" />
<!-- v-bind props --> <!-- v-bind props -->
<Foo checked /> <Foo checked />
<!-- 绑定对象 -->
<Foo id="bindObj1" v-bind="{ title: dataInfo.fooProps.title,num: dataInfo.fooProps.num,obj: dataInfo.fooProps.obj }" />
<!-- 绑定对象合并-->
<Foo id="bindObj2" v-bind="{ title: dataInfo.fooProps.title,num: dataInfo.fooProps.num,obj: dataInfo.fooProps.obj }" title="foo title override" />
<!-- 绑定对象合并-->
<Foo id="bindObj3" title="foo" v-bind="{ title: dataInfo.fooProps.title,num: dataInfo.fooProps.num,obj: dataInfo.fooProps.obj }" />
<!-- 绑定对象合并(UTSJSONObject)-->
<Foo id="bindObj4" v-bind="fooProps" title="foo title(json) override" />
<!-- 绑定对象合并(UTSJSONObject)-->
<Foo id="bindObj5" title="foo" v-bind="fooProps" />
<!-- v-bind in style --> <!-- v-bind in style -->
<!-- #ifdef WEB --> <!-- #ifdef WEB -->
<view class="mb-10 v-bind-css"></view> <view class="mb-10 v-bind-css"></view>
<!-- #endif --> <!-- #endif -->
</view> </view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
...@@ -60,7 +77,12 @@ ...@@ -60,7 +77,12 @@
}, },
vBindClassBackgroundColor: 'red', vBindClassBackgroundColor: 'red',
vBindClassRpxHeight: '300rpx' vBindClassRpxHeight: '300rpx'
} as DataInfo) } as DataInfo)
const fooProps = reactive({
title: 'foo title(json)',
num: 2,
})
defineExpose({ defineExpose({
dataInfo dataInfo
......
<template> <template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="page"> <view class="page">
<!-- v-bind attribute --> <!-- v-bind attribute -->
<button id="disabled-btn" class="mb-10" :disabled="true">:disabled true</button> <button id="disabled-btn" class="mb-10" :disabled="true">:disabled true</button>
...@@ -21,13 +24,29 @@ ...@@ -21,13 +24,29 @@
<Foo :title="dataInfo.fooProps.title" :num="dataInfo.fooProps.num" :obj="dataInfo.fooProps.obj" /> <Foo :title="dataInfo.fooProps.title" :num="dataInfo.fooProps.num" :obj="dataInfo.fooProps.obj" />
<!-- v-bind props --> <!-- v-bind props -->
<Foo checked /> <Foo checked />
<!-- 绑定对象 -->
<Foo v-bind="{ title: dataInfo.fooProps.title,num: dataInfo.fooProps.num,obj: dataInfo.fooProps.obj }" />
<Foo v-bind="fooProps"/>
<Foo id="bindObj1" v-bind="{ title: dataInfo.fooProps.title,num: dataInfo.fooProps.num,obj: dataInfo.fooProps.obj }" />
<!-- 绑定对象合并 v-bind 在前 -->
<Foo v-bind="{ title: dataInfo.fooProps.title,num: dataInfo.fooProps.num,obj: dataInfo.fooProps.obj }" id="bindObj2" :title="dataInfo.fooProps.title + ' override'" />
<!-- 绑定对象合并 v-bind 在后 -->
<Foo id="bindObj3" title="foo" v-bind="{ title: dataInfo.fooProps.title,num: dataInfo.fooProps.num,obj: dataInfo.fooProps.obj }" />
<!-- 绑定对象合并 v-bind 在中间(UTSJSONObject)-->
<Foo id="bindObj4" v-bind="fooProps" title="foo title(json) override" />
<!-- 绑定对象合并(UTSJSONObject)-->
<Foo id="bindObj5" title="foo" v-bind="fooProps" />
<!-- v-bind in style --> <!-- v-bind in style -->
<!-- #ifdef WEB --> <!-- #ifdef WEB -->
<view class="mb-10 v-bind-css"></view> <view class="mb-10 v-bind-css"></view>
<!-- #endif --> <!-- #endif -->
</view> </view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template> </template>
<script lang="uts"> <script lang="uts">
...@@ -60,7 +79,11 @@ ...@@ -60,7 +79,11 @@
}, },
vBindClassBackgroundColor: 'red', vBindClassBackgroundColor: 'red',
vBindClassRpxHeight: '300rpx' vBindClassRpxHeight: '300rpx'
} as DataInfo } as DataInfo,
fooProps:{
title: 'foo title(json)',
num: 2,
}
} }
} }
} }
......
...@@ -44,8 +44,19 @@ describe('v-bind', () => { ...@@ -44,8 +44,19 @@ describe('v-bind', () => {
const fooPropsNum = await page.$('#foo-props-num') const fooPropsNum = await page.$('#foo-props-num')
expect(await fooPropsNum.text()).toBe(dataInfo.fooProps.num.toString()) expect(await fooPropsNum.text()).toBe(dataInfo.fooProps.num.toString())
const fooPropsObjName = await page.$('#foo-props-obj-name') const fooPropsObjName = await page.$('#foo-props-obj-name')
expect(await fooPropsObjName.text()).toBe(dataInfo.fooProps.obj.name) expect(await fooPropsObjName.text()).toBe(dataInfo.fooProps.obj.name)
const bindObj1 = await page.$('#bindObj1')
expect(await (await bindObj1.$('#foo-props-title')).text()).toBe(dataInfo.fooProps.title)
const bindObj2 = await page.$('#bindObj2')
expect(await (await bindObj2.$('#foo-props-title')).text()).toBe(dataInfo.fooProps.title+' override')
const bindObj3 = await page.$('#bindObj3')
expect(await (await bindObj3.$('#foo-props-title')).text()).toBe(dataInfo.fooProps.title)
const bindObj4 = await page.$('#bindObj4')
expect(await (await bindObj4.$('#foo-props-title')).text()).toBe(`foo title(json) override`)
const bindObj5 = await page.$('#bindObj5')
expect(await (await bindObj5.$('#foo-props-title')).text()).toBe(`foo title(json)`)
if (isWeb) { if (isWeb) {
const vBindCss = await page.$('.v-bind-css') const vBindCss = await page.$('.v-bind-css')
expect(await vBindCss.style('backgroundColor')).toBe('rgb(255, 0, 0)') expect(await vBindCss.style('backgroundColor')).toBe('rgb(255, 0, 0)')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册