0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

상품선택(구현하지 못하고 있음)

Posted at

몇일동안 고생해서 작업했지만
생각한것을 구현하지는 못했다.

<template>
  <div>
    <div>
      <h1>매일 먹는거</h1>
      <swiper
        
        class="swiper"
        :modules="modules"
        :space-between="10"
        :slides-per-view="3"
        :free-mode="true"
        :pagination="{ clickable: true }"
      >
        <swiper-slide
          v-for="(food,index) in foodList"
          :key="index"
          class="slide"
        >
          <div
            :key="index"
            :class="{'active' :isActive === index}"
            @click="addToCart(food,index)"
          >
            {{ index }}
            <!-- <img :src="food.image"> -->
            <div>
              <span>
                {{ food.name }}       
              </span>
            </div>        
          </div>
        </swiper-slide>
      </swiper>
    </div>
    <h1>자주 먹는거</h1>
    <h1>가끔 먹는거</h1>
    <h1>애들 먹는거</h1>
  </div>
</template>

<script>
import { defineComponent } from 'vue'
import {mapState} from 'vuex';
import { Pagination,FreeMode } from 'swiper'
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'

// import swiper module styles
import 'swiper/css'
import 'swiper/css/pagination'
import 'swiper/css/free-mode'
// more module style...

export default defineComponent({    
    name: 'SwiperExampleFreeMode',
    title: 'Free mode / no fixed positions',
    url: import.meta.url,    
    components: {
      Swiper,
      SwiperSlide
    },
    setup() {
      return {
        modules: [Pagination, FreeMode]
      }
    },
   data(){
     return {
       isActive:null

     }
   },

  computed:{
      ...mapState('foodListModule',["foodList"])
  },
  created(){
    this.$store.dispatch("foodListModule/setFoodList");
  },  
  methods:{
    addToCart(food,index) {
      this.$store.dispatch("foodListModule/addToCart", food);
      if(this.isActive === index){
          this.isActive = null;
        }else{
          this.isActive = index;
        }
    },  
  },    
  })
</script>
<style lang="scss" scoped>
  @import '@/styles/init.scss';
  @import './style.scss';

  .swiper {
    @include swiper-wrapper();
  }

  .slide {
    @include swiper-slide();
  }

  .active {border:solid 3px red}
</style>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?