I have this search input:
<input
class="form-control"
type="text"
name="search"
placeholder="search..."
v-model="search"
/>
And this "output" area:
<my-comp
v-for="item in filter"
:key="item.id"
:id="item.id"
:imgsrc="item.imgsrc"
:price="item.price"
:city="item.city"
:country="item.country"
:reviewnum="item.reviewnum"
:daynum="item.daynum"
/>
i imort data from json file and this is the data
[
{"id": 1, "city":"California", "country": "United State of America", "price": "700", "reviewnum": "890", "daynum": "5", "imgsrc": "img/place/1.png"},
{"id": 2, "city":"london", "country": "United Kingdom", "price": "550", "reviewnum": "900", "daynum": "4", "imgsrc": "img/place/2.png"},
{"id": 3, "city":"Korola Megna", "country": "Nepal", "price": "350", "reviewnum": "150", "daynum": "5", "imgsrc": "img/place/3.png"},
{"id": 4, "city":"Miami Beach", "country": "United State of America", "price": "850", "reviewnum": "660", "daynum": "7", "imgsrc": "img/place/4.png"},
{"id": 5, "city":"California", "country": "United State of America", "price": "600", "reviewnum": "380", "daynum": "6", "imgsrc": "img/place/5.png"},
{"id": 6, "city":"Saintmartine Iceland", "country": "Kingdom of the Netherlands", "price": "450", "reviewnum": "340", "daynum": "3", "imgsrc": "img/place/6.png"}
]
The idea is that the user searches a city or country or any data and the output should show only the cards he is searching for.
This is the vue js code:
import data from "@/assets/data.json";
export default {
name: "Home",
data: function () {
return {
allData: data,
search: "",
};
},
components: { myComp, foooter, headeer },
computed: {
filter() {
if (!this.search) {
return this.allData;
} else {
return this.allData.filter(({ country }) =>
(country).toLowerCase().includes(this.search.toLowerCase())
);
}
},
},
};
But my function only accepts one variable. What should I do?