fix(Card): render correctly when the price is an integer (#12917)

This commit is contained in:
inottn 2024-06-05 22:28:05 +08:00 committed by GitHub
parent f937005f2b
commit 4d1e1b5871
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 2 deletions

View File

@ -108,8 +108,12 @@ export default defineComponent({
return (
<div>
<span class={bem('price-currency')}>{props.currency}</span>
<span class={bem('price-integer')}>{priceArr[0]}</span>.
<span class={bem('price-decimal')}>{priceArr[1]}</span>
<span class={bem('price-integer')}>{priceArr[0]}</span>
{priceArr.length > 1 && (
<>
.<span class={bem('price-decimal')}>{priceArr[1]}</span>
</>
)}
</div>
);
};

View File

@ -44,6 +44,7 @@ exports[`should render demo and match snapshot 1`] = `
<span class="van-card__price-integer">
2
</span>
<!--[-->
.
<span class="van-card__price-decimal">
00
@ -109,6 +110,7 @@ exports[`should render demo and match snapshot 1`] = `
<span class="van-card__price-integer">
2
</span>
<!--[-->
.
<span class="van-card__price-decimal">
00
@ -183,6 +185,7 @@ exports[`should render demo and match snapshot 1`] = `
<span class="van-card__price-integer">
2
</span>
<!--[-->
.
<span class="van-card__price-decimal">
00

View File

@ -86,3 +86,13 @@ test('should render price and price-top slot correctly', () => {
expect(wrapper.html()).toMatchSnapshot();
});
test('should render correctly when the price is an integer', () => {
const wrapper = mount(Card, {
props: {
price: 12,
},
});
expect(wrapper.find('.van-card__price').text()).toEqual('¥12');
});

View File

@ -115,6 +115,7 @@ exports[`should render demo and match snapshot 1`] = `
<span class="van-card__price-integer">
2
</span>
<!--[-->
.
<span class="van-card__price-decimal">
00