최대 1 분 소요

1. 프로젝트 시작

# terminal

$ npx degit LeeWonWoo1/vue3-webpack-template vue3-test
$ cd vue3-webpack-template vue3-test
$ code . -r
$ npm i

2. 조건문

// src/App.vue


<template>
  <h1 @click="increase">
    8
  </h1>
  <div v-if="count > 4">  // 조건문 작성
    4보다 큽니다!
  </div>
</template>

<script>
  data() {
    return {
      count: 0,
    }
  },
  methods: {
    increase() {
      this.count += 1
    }
  }
}
</script>

<style lang="scss">
  h1 {
    font-size: 50px;
    color: royalblue;
  }
  ul {
    li {
      font-size: 40px;
    }
  }
</style>>


vue5


3. 반복문

// src/App.vue

<template>
  <h1 @click="increase">
    8
  </h1>
  <div v-if="count > 4">
    4보다 큽니다!
  </div>
  <ul>  // 반복문
    <Fruit 
      v-for="fruit in fruits"
      :key="fruit"
      :name="fruit">
      
    </Fruit>
  </ul>
</template>

<script>
import Fruit from '~/components/Fruit'

export default {
  components: {
    Fruit
  },
  data() {
    return {
      count: 0,
      fruits: ['Apple', 'Banana', 'Cherry']
    }
  },
  methods: {
    increase() {
      this.count += 1
    }
  }
}
</script>

<style lang="scss">
  h1 {
    font-size: 50px;
    color: royalblue;
  }
  ul {
    li {
      font-size: 40px;
    }
  }
</style>>


// src/components/Fruit.vue

<template>
  <li>?!</li>
</template>

<script>
export default {
  props: {
    name: {
      type: String,
      default: ''
    }
  }
}
</script>

<style scoped lang="scss">
  h1 {
    color: red !important;
  }
</style>


vue6

댓글남기기