0

i have this code below in Vue Js and i've implemented filter to API array elements and works fine, now i'm trying to set a button that clears the filter when i click on it and returns the page as nothing changes but my code below didn't work it shows empty array questions, any help please? and thanks in advance

<template> <div class="container" width=800px> <b-row> <b-col cols="8"> <h1> Recently Asked </h1> <ul class="container-question" v-for="(question1,index) in questions" :key="index" > <li> {{question1.question}} </li></ul> </b-col> <b-button class="outline-primaryy" style="margin:auto;" @click="ClearFilter" :disabled="selectedIndex === index ">Clear Filter</b-button> </div> <router-view /> </div> </template> <script> export default { data(){ return{ questions: [], answered: null, index: 0, selectedIndex: null, } }, methods: { selectedAnswer(index) { this.selectedIndex = index; this.questions=this.questions.filter((question) => question.incorrect_answers.includes(index)) console.log(index) }, ClearFilter(){ this.questions = [] }, watch: { question1: { handler() { this.selectedIndex = null; this.answered = false; }, }, }, }, mounted: function(){ fetch('https://opentdb.com/api.php?amount=10&category=9&difficulty=medium&type=multiple',{ method: 'get' }) .then((response) => { return response.json() }) .then((jsonData) => { this.questions = jsonData.results }) }, } </script>

1 Answer 1

1

I'm not sure if got your question correctly. But this may help:

.then((jsonData) => { this.questions = jsonData.results; this.unmutated = jsonData.results; }) 

when you click the reset button

this.questions = this.unmutated 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.