0
VueJSコンポーネントは、ナビゲーション後にキャッシュされたり、少なくとも再接続されません。リフレッシュまたは起動時に、すべてがアタッチされてレンダリングされますが、別のページに移動してから戻った後に表示されます。私の場合、最初のComponent - Carouselコンポーネントはレンダリングされませんが、API呼び出しが行われます。Vue JSコンポーネント再接続またはキャッシュ
<template>
<div class="rel">
<div id="homeCarousel" class="owl-carousel owl-slider">
<div class="item" v-for="product in featured">
<div class="bg-holder top-area-half" >
<div class="bg-mask-lighten"></div>
<img class="bg-img" v-bind:src="product.feature_image_url">
<div class="hero-caption">
<div class="container">
<h3 class="hero-title">{{product.feature_title}}</h3>
<p class="hero-subtitle">{{product.feature_subtitle}}</p>
<a class="btn btn-white btn-ghost btn-lg hero-btn" href="#">Shop now</a>
</div>
</div>
</div>
</div>
</div>
<div id="hero-slider-nav" class="hero-slider-nav">
<div class="container">
<div class="pull-right"></div>
</div>
</div>
</div>
</template>
<style>
</style>
<script>
export default{
data(){
return{
featured:[]
}
},
ready(){
},
mounted(){
this.getFeaturedProducts();
},
components:{
},
methods: {
getFeaturedProducts: function() {
Vue.http.get('/api/product/filter/featured=1').then(
(response) => {
this.featured = response.body;
}
)
}
}
}
</script>
`
<template>
<div class="global-wrapper clearfix ">
<keep-alive>
<Carousel></Carousel>
</keep-alive>
//The rest of the code which is just importing the Component
あなたは 'keep-alive'オプションなしで試しましたか?一度レンダリングしてもう一度レンダリングしない場合は、キープアライブの問題である可能性が最も高い – Mani
私はそれを気にせずに試してみました。戻ってナビゲートするとレンダリングされません。 – user3533087
次に、 'this.featured' [vue-cli](https://github.com/vuejs/vue-cli)を使用して、期待する製品配列があることを確認してください。配列の長さがゼロの場合、表示されている要素は表示されませんが、コンポーネントがレンダリングされる可能性があります。 – Mani