Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit406c7da

Browse files
committed
🔨 Refactor Slideshow component
activeIndex props 추가- 상위 컴포넌트에서 curIdx를 조정할 수 있도록 수정
1 parent9420b34 commit406c7da

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

‎src/components/images/Slideshow.vue‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,34 @@ export default {
4444
},
4545
isGallery:Boolean,
4646
showDots:Boolean,
47-
overlapText:Boolean
47+
overlapText:Boolean,
48+
activeIndex: {
49+
type:Number,
50+
default:0
51+
}
4852
},
4953
data() {
5054
return {
51-
curIdx:0
55+
curIdx:this.activeIndex
5256
}
5357
},
5458
computed: {
5559
slideLength() {
5660
returnthis.slides.length
5761
}
5862
},
63+
watch: {
64+
activeIndex() {
65+
if (this.curIdx!==this.activeIndex) {
66+
this.curIdx=this.activeIndex
67+
}
68+
}
69+
},
5970
methods: {
6071
changeSlide(num) {
6172
this.curIdx=this.slideLength<= num?0: num
62-
this.$emit('change-slide', num)
73+
this.$emit('change-slide',this.curIdx)
74+
this.$emit('update:activeIndex',this.curIdx)
6375
},
6476
prevSlide() {
6577
this.changeSlide(this.curIdx>0?this.curIdx-1:this.slideLength-1)

‎test/unit/components/images/Slideshow.test.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ describe('Slideshow.vue', () => {
102102
})
103103
})
104104

105+
it('props#activeIndex',()=>{
106+
constpropsData={ slides,activeIndex:1}
107+
constwrap=mount(Slideshow,{ propsData})
108+
109+
expect(wrap.vm.curIdx).toEqual(1)
110+
111+
wrap.vm.changeSlide(0)
112+
113+
expect(wrap.vm.curIdx).toEqual(0)
114+
115+
const$activeIndex=wrap.emitted()['update:activeIndex']
116+
expect($activeIndex.length).toEqual(1)
117+
expect($activeIndex[0]).toEqual([0])
118+
119+
renderer.renderToString(wrap.vm,(err,str)=>{
120+
if(err)console.error(err)
121+
expect(str).toMatchSnapshot()
122+
})
123+
})
124+
105125
it('props#is-gallery',()=>{
106126
constpropsData={ slides,isGallery:true}
107127
constwrap=mount(Slideshow,{ propsData})

‎test/unit/components/images/__snapshots__/Slideshow.test.js.snap‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ exports[`Slideshow.vue methods@prevSlide 2`] = `
100100
</div>
101101
`;
102102
103+
exports[`Slideshow.vue props#activeIndex 1`] = `
104+
<divclass="slideshow">
105+
<divclass="slideshow-container">
106+
<divclass="slide fade is-active">
107+
<divclass="numbertext">1 / 2</div> <imgsrc="https://www.w3schools.com/howto/img_nature_wide.jpg"alt="Caption Text">
108+
<divclass="text">
109+
<p>Caption Text</p>
110+
</div>
111+
</div>
112+
<divclass="slide fade">
113+
<divclass="numbertext">2 / 2</div> <imgsrc="https://www.w3schools.com/howto/img_fjords_wide.jpg"alt="Caption Two">
114+
<divclass="text">
115+
<p>Caption Two</p>
116+
</div>
117+
</div> <aclass="prev">❮</a> <aclass="next">❯</a></div>
118+
<!----><br>
119+
<!---->
120+
</div>
121+
`;
122+
103123
exports[`Slideshow.vue props#is-gallery 1`] = `
104124
<divclass="slideshow">
105125
<divclass="slideshow-container">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp