Skip to content

Commit

Permalink
fix(swiper): 修复 swiper-item 宽高错误问题 (#2679)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiinu authored Nov 20, 2023
1 parent 8c06310 commit 8aa869f
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 26 deletions.
2 changes: 0 additions & 2 deletions src/packages/__VUE/address/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ export default create({
}
});
console.log('new', newData);
return newData;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('should render width and height', async () => {
'nut-swiper-item': SwiperItem
},
template: `
<nut-swiper :init-page="page" :pagination-visible="true" pagination-color="#426543" auto-play="2000" :height="height">
<nut-swiper :init-page="page" :pagination-visible="true" pagination-color="#426543" auto-play="2000" :height="height" :width="width">
<nut-swiper-item v-for="item in list" :key="item">
<img :src="item" alt="" />
</nut-swiper-item>
Expand All @@ -21,7 +21,8 @@ test('should render width and height', async () => {
setup() {
const state = reactive({
page: 1,
height: '500',
width: 300,
height: 500,
list: [
'https://storage.360buyimg.com/jdc-article/NutUItaro34.jpg',
'https://storage.360buyimg.com/jdc-article/NutUItaro2.jpg',
Expand All @@ -40,7 +41,7 @@ test('should render width and height', async () => {
const swiperItem = wrapper.findAll('.nut-swiper-inner')[0].element as HTMLElement;

expect(swiperItem.style.height).toEqual(`${wrapper.vm.height}px`);
expect(swiperItem.style.width).toEqual(`${window.innerWidth * (wrapper.vm.list as any).length}px`);
expect(swiperItem.style.width).toEqual(`${wrapper.vm.width * (wrapper.vm.list as any).length}px`);
});

test('should render initpage', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/packages/__VUE/swiper/doc.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ const page = ref(2);

| Attribute | Description | Type | Default |
| --- | --- | --- | --- |
| width | Width of rotation card | number \| string | `window.innerWidth ` |
| height | Height of rotation card | number \| string | `0` |
| width | Width of rotation card | number \| string | - |
| height | Height of rotation card | number \| string | - |
| direction | Rotation direction, optional value:`horizontal`,`vertical` | string | `'horizontal'` |
| pagination-visible | Is the paging indicator displayed | boolean | `false` |
| pagination-color | The color selected by the pagination indicator | string | `'#fff'` |
Expand Down
4 changes: 2 additions & 2 deletions src/packages/__VUE/swiper/doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ const page = ref(2);

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| width | 轮播卡片的宽度 | number \| string | `window.innerWidth` |
| height | 轮播卡片的高度 | number \| string | `0` |
| width | 轮播卡片的宽度 | number \| string | - |
| height | 轮播卡片的高度 | number \| string | - |
| direction | 轮播方向,可选值`horizontal`,`vertical` | string | `'horizontal'` |
| pagination-visible | 分页指示器是否展示 | boolean | `false` |
| pagination-color | 分页指示器选中的颜色 | string | `'#fff'` |
Expand Down
4 changes: 2 additions & 2 deletions src/packages/__VUE/swiper/doc.taro.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ const page = ref(2);

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| width | 轮播卡片的宽度 | number \| string | window.innerWidth |
| height | 轮播卡片的高度 | number \| string | `0` |
| width | 轮播卡片的宽度 | number \| string | - |
| height | 轮播卡片的高度 | number \| string | - |
| direction | 轮播方向,可选值`horizontal`,`vertical` | string | `'horizontal'` |
| pagination-visible | 分页指示器是否展示 | boolean | `false` |
| pagination-color | 分页指示器选中的颜色 | string | `'#fff'` |
Expand Down
18 changes: 8 additions & 10 deletions src/packages/__VUE/swiper/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ const { create, componentName } = createComponent('swiper');
export default create({
props: {
width: {
type: [Number, String],
default: window.innerWidth
type: [Number, String]
},
height: {
type: [Number, String],
default: 0
type: [Number, String]
},
direction: {
type: String,
Expand Down Expand Up @@ -416,24 +414,24 @@ export default create({
watch(
() => props.initPage,
() => {
(val) => {
Taro.nextTick(() => {
init();
init(+val);
});
eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
init();
init(+val);
});
}
);
watch(
() => props.height,
(val) => {
() => {
Taro.nextTick(() => {
init(+val);
init();
});
eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
init(+val);
init();
});
}
);
Expand Down
6 changes: 2 additions & 4 deletions src/packages/__VUE/swiper/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ const { create, componentName } = createComponent('swiper');
export default create({
props: {
width: {
type: [Number, String],
default: window.innerWidth
type: [Number, String]
},
height: {
type: [Number, String],
default: 0
type: [Number, String]
},
direction: {
type: String,
Expand Down
1 change: 0 additions & 1 deletion src/packages/__VUE/video/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ export default create({
};
const retry = () => {
// console.log('error');
state.state.isError = false;
init();
};
Expand Down

0 comments on commit 8aa869f

Please sign in to comment.