小白求组,试了keepAlive的方法也不行,求大神帮看看
APP.vue
<keep-alive>
<router-view></router-view>
</keep-alive>
router
{
path: '/goods/:goodId',
name: "goodsdetail",
component: Goods,
meta:{keepAlive:false}
},
商品页
<template>
<a class="recommend-item" @click.stop="$router.push({name:'goodsdetail', params:{ goodId:rec.goods_id }})">
<img v-lazy="rec.thumb_url" alt="" width="100%" v-if="rec.thumb_url">
<h4 class="item-title">{{rec.short_name}}</h4>
<div class="item-bottom">
<span class="item-price">¥{{rec.price / 100}}</span>
<span class="item-sales">{{rec.sales_tip}}</span>
<button class="item-btn" @click="clickCellBtn(rec)"><i class="icon-6"></i></button>
</div>
</a>
</template>
商品详情页
export default {
name: "GoodsDetail",
data() {
return {
id: this.$route.params.goodId,
}
},
computed: {
...mapState(['goods_detail'])
},
activated() {
this.fetchData();
},
watch: {
goods_detail() {
this.$nextTick(() => {
// 创建swiper的实例
new Swiper('.swiper-container', {
autoplay: true,//等同于以下设置
loop: true,
// 如果需要分页器
pagination: {
el: '.swiper-pagination',
}
});
});
},
},
methods:{
fetchData(){
let goods_id = this.id;
this.$store.dispatch('getDetail',{goods_id});
}
},
}
</script>