I am trying to write an if and else statement using props as rules and not sure how to construct it fully correctly. In router I have this:
{
path: '/CardDisplay/:type',
name: 'CardDisplay',
props: true,
component: () => import('./views/CardDisplay.vue')
},
{
path: '/CardDisplay/find/:movie',
name: 'CardDisplay',
props: true,
component: () => import('./views/CardDisplay.vue')
},
And then I pass two props in another vue file type and movie. Depending on a call either movie or type is going to be undefined so I wanted to write if else statement that will surround api fetch and currently page looks like this:
<template>
<div>
<movie-cards></movie-cards>
</div>
</template>
<script>
import MovieCards from '@/components/MovieCards';
import HomePlans from '@/components/HomePlans';
export default {
name: 'CardDisplay',
props:["type", "movie"],
components: {
MovieCards,
HomePlans
},
methods: {
getResults(props){
if(this.movie =="undefined"){
apiCall(isUpcoming){
const apiType = isUpcoming ? 'upcoming' : 'top_rated';
const url = `https://api.themoviedb.org/3/movie/${apiType}?api_key=api key&language=en-US&page=1`;
const response = await fetch(url);
let data = await response.json();
if (response.ok) {
this.results = data.results;
this.error = '';
} else {
this.results = [];
this.error = data.errors[0];
}
}
}else{
searchCall(searchTerm){
const urls = `https://api.themoviedb.org/3/search/movie?api_key=apikey&language=en-US&query=`;
const API_URL = `${urls}${this.searchTerm}`;
const responses = await fetch(API_URL);
let data = await responses.json();
if (responses.ok) {
this.results = data.results;
this.error = '';
} else {
this.results = [];
this.error = data.errors[0];
}
}
}
}
},
};
</script>
<style scoped>
</style>
However, it gives me errors inside the if statement after apiCall(isUpcoming){ and it underlines the "{" saying expected ; and it wont compile.
I added getResults that surrounds everything but Im not sure whether that is even necessary.