Created
February 5, 2022 04:01
-
-
Save badasscodr/978791e894f0951ae9f3134cbf40dfa6 to your computer and use it in GitHub Desktop.
slider issue. - sigmawebstore by ali
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello Developers | |
There is a slider component. I am making slides dynamic. There two approaches. | |
Case 1: | |
There is an array in data() option. Here | |
Static-- | |
<template> | |
<div> | |
<li>1</li> | |
<li>2</li> | |
<li>3</li> | |
</div> | |
</template> | |
Dynamic-- | |
<template> | |
<div> | |
<li v-for="(slide, index) in slides" :key="index"> | |
{{ slide.title }} | |
</li> | |
</div> | |
</template> | |
data () { | |
return { | |
slides: [ | |
{ | |
id: 1, | |
title: "Best Handmade Goods", | |
}, | |
{ | |
id: 2, | |
title: "Best Cotton", | |
}, | |
], | |
} | |
} | |
Result: Working Perfect | |
Case 2 | |
<template> | |
<div> | |
<li v-for="(slide, index) in slides" :key="index"> | |
{{ slide.title }} | |
</li> | |
</div> | |
</template> | |
data () { | |
return { | |
slides: null | |
} | |
}, | |
methods: { | |
async fetchSlides() { | |
try { | |
const url = "https://fakestoreapi.com/products" | |
const response = await axios.get(url) | |
this.slides = response.data | |
console.log(this.slides) | |
} catch (error) { | |
console.log(error) | |
} | |
} | |
} | |
Result for case 2: UI break. Slider stop working while API call. | |
I am expecting a solution from you developers. Please |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment