0
이 SearchResult 구성 요소는 vue-router에 의해 호출 될 때 YouTube API v3에서 객체를 가져옵니다. 수신 된 객체는 수십 개의 하위 구성 요소에 대한 소품으로 전달됩니다. 나는 경로를 바꾸고이 분대를 표시하기 위하여 $router.push(/search/ + this.query)
를 사용하는 수색 막대가있다.
문제는 처음으로 또는 다른 경로에서 검색을 사용할 때 매우 좋습니다. 하지만 다시 검색 할 때 은에서 API의 새로운 결과로 다시 렌더링하지 않습니다. 비록 내가 시계를 추가했습니다 this.$route.params.query
. 다음은 SearchResult.vue 구성 요소입니다.
<template>
<div>
<app-banner></app-banner>
<div v-if="resultIds">
<div v-for="resId in resultIds.items">
<vid-preview :vidId="resId.id.videoId"></vid-preview>
</div>
</div>
</div>
</template>
<script>
import axios from 'axios'
export default {
data() {
return {
resultIds: null,
errors: []
}
},
watch: {
'$route.params.query' (newQuery, oldQuery) {
this.$router.push('/search/' + newQuery) //This code executes but no change visible on screen.
}
},
created() {
axios.get(`https://www.googleapis.com/youtube/v3/search/`, {
params: {
part: 'id',
q: this.$route.params.query,
order: 'relevance',
maxResults: '50',
key: '{API KEY}'
}
}).then(res => {
this.resultIds = res.data;
}).catch(e => {
this.errors.push(e);
})
}
}
</script>
, 나는 코드 : –
없음 문제처럼 만들려고 노력했다. 다음 번에 코드 블록을 강조 표시하고 편집기 도구에서'{}'을 클릭하십시오 – samayo
작은 따옴표 안에 $ route.params.query가 없습니까 ?? –