19~20일차


21일차


22일차

 

- addClass

    active(index) {
      var element = document.getElementsByClassName("wordButton");
      element[index].classList.add("unClick");
    },

한개의 버튼만 class를 추가할때는 id로 접근해도 되지만 여러개의 버튼에 class를 추가하고 싶다면

class로 접근 접근해야 한다 그리고

element[index] 꼭!! 해당 버튼만 class를 추가하고 싶다면 배열의 인덱스에 접근해야 한다

 

- checked

    if(state.checked == 0 || state.checked == 4) {
      state.checked = 1
    }

스페인어만 보기, 한국어만 보기, 랜덤 보기, 누른 상태에서

단어를 추가하게 되면 전체보기로 가게되는 오류 수정

단 랜덤 보기 일때는 전체보기로 이동 

 


23일차(단어장, 날씨 css완성)

전체보기

랜덤 보기

 

// html

      <div class="AllWordTable">
        <div class="dayAddTable" v-for="randomWord in randomWord">

          <div class="dayWordTable" v-for="randomWord in randomWord"  v-if="checked===4">
           <span class="wordContent"> {{randomWord[0]}}</span>
           <span class="wordContent"> {{randomWord[1]}}</span>
          </div>

        </div>
      </div>
// css

  .AllWordTable {
    width: 100%;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .dayAddTable {
    width: 45%;
    margin: 1%;
  }

  .dayWordTable {
    width: 100%;
    background: azure;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;

  }
  .wordContent {
    width: 49%;
    border: 1px solid gray;
    text-align: center;
    height: 40px;
  }

.AllWordTable - 선택한 날짜 전체 단어장 box ( ex:1~4일차 단어장 전체)

.dayAddTable - 날짜별 단어장 box ( ex:1~4일차 중 1일차 단어장)

.dayWordTable - 스페인어 : 한국어 1줄 ( ex: 1일차 단어장 중 첫번째줄)

.wordContent - 스페인어 OR 한국어 ( ex: 첫번째줄 중 한국어 or 스페인어)

 

1. AllWordTable 크기를 100%로 잡고 flex를 이용해서 100%를 넘어가면 줄바꿈

2. dayAddTable 크기를 45%로 잡아서 가로에 최대 2일차까지만 화면에 보이게 만들기

 

3. dayWordTable 크기를 100%로 잡고 flex를 이용해서 100%를 넘어가면 줄바꿈

4. wordContent 크기를 50%로 잡아서 한줄에 스페인어 : 한국어 모양으로 줄바꿈

 

날 씨

24,25일차(비트코인 로딩, 차트 css완성)

1. (로딩 페이지)

2. (로딩 후 페이지)

3. (코인 클릭 후 차트)

 

-가장 많이 오른 코인

-가장 많이 떨어진 코인

 

앞으로 할일
- grid 이용해서 단어장 꾸미기
- 날씨 컴포넌트 꾸미기
- 비트코인 컴포넌트 꾸미기
- 메뉴 버튼 꾸미기
- 메인 꾸미기

단어장 날짜 선택할때 중복 클릭 방지 및 단어장 더 추가하기

showAll({state, commit}, data) {
    // showWord 안에 값이 클릭햇을때 값이랑 같으면 중복 콘솔찍기
    // 다르면 showWord에 push하기
    if(state.showWord.length === 0) {
      commit('SELECT_WORD', data)
    }
    for(var i=0; i<state.showWord.length; i++) {
      for(var j=0; j<state.showWord.length; j++) {
        if(data[0] === state.showWord[j][0]) {
          return 0
        }
      }
      return commit('SELECT_WORD', data)
    }
    state.checked = 1
  },

여러 단어장 선택했을때 랜덤으로 보기 수정

showRandom({state, commit}) {
    if(state.randomWord !== []) {
      state.randomWord = []
    }
    state.randomWord = JSON.parse(JSON.stringify(state.showWord))
    for(var i=0; i<state.randomWord.length; i++){

      for(var j=0; j<state.randomWord[i].length; j++) {
        state.randomNumber = parseInt(Math.random()*10%2)
        if(state.randomNumber === 0) {
          state.randomWord[i][j][0] = ' '
        } else {
          state.randomWord[i][j][1] = ' '
        }
      }

    }
    state.randomWord.sort()
    state.checked = 4

'Vue-프로젝트' 카테고리의 다른 글

vue-프로젝트 CSS(19일차 ~)  (0) 2020.05.13
vue-프로젝트 단어장(17일차)  (0) 2020.04.28
vue-프로젝트 단어장(16일차)  (0) 2020.04.27
vue-프로젝트 vuex Helper(15일차)  (0) 2020.04.24
vue-프로젝트 vuex(14일차)  (0) 2020.04.23
할일
- 랜덤 버튼 누를때 한국어 스페인어 랜덤으로 화면에 보이기

내일 할일
- grid 이용해서 단어장 꾸미기

앞으로 할일
- 날씨 컴포넌트 꾸미기
- 비트코인 컴포넌트 꾸미기
- 메뉴 버튼 꾸미기
- 메인 꾸미기



배열을 복사 하는법에는 깊은복사 얕은복사가  있다.

랜덤 버튼 누를때 한국어 스페인어 랜덤으로 화면에 보이기

  showRandom({state, commit}) {
    if(state.randomWord !== []) {
      state.randomWord = []
    }
    state.randomWord = JSON.parse(JSON.stringify(state.showWord))

    for(var i=0; i<state.randomWord.length; i++){
      state.randomNumber = parseInt(Math.random()*10%2)
      if(state.randomNumber === 0) {
        state.randomWord[i][0] = ' '
      } else {
        state.randomWord[i][1] = ' '
      }
    }
    state.checked = 4

1. 해당 단어장 randomWord에 깊은 복사

2. randomNumber(랜덤숫자) 2로 나눴을때

   나머지 === 1 -> 한국어 가리기

   나머지 === 0 -> 스페인어 가리기

 

day1 랜덤 버튼클릭

day2 랜덤 버튼클릭

 

'Vue-프로젝트' 카테고리의 다른 글

vue-프로젝트 CSS(19일차 ~)  (0) 2020.05.13
vue-프로젝트 단어장(18일차)  (0) 2020.04.30
vue-프로젝트 단어장(16일차)  (0) 2020.04.27
vue-프로젝트 vuex Helper(15일차)  (0) 2020.04.24
vue-프로젝트 vuex(14일차)  (0) 2020.04.23
내일 할일
- 단어장 초기화 하기(jsonWord내용도 바뀜 sort 문제 같음)
- 섞어서 볼때 한국어 스페인어 랜덤
- grid 이용해서 꾸미기
// spanishWord.js

import jsonWord from '../../json/word.json'

//vue의 data와 비슷
const state = {
  getWord: [],
  checked: '',
  showWord: [],
  randomWord: [],
}
// vue의 computed와 비슷
const getters = {

}
// state를 수정할 때 사용
const mutations = {
  SET_WORD(state, data) {
    if(state.getWord.length < Object.keys(jsonWord).length) {
      state.getWord.push(data)
    }
  },
  SELECT_WORD(state, data) {
    state.showWord = data
    console.log(data)
  },
  SET_RANDOMWORD(state, data) {
    state.randomWord.push(data)
  },

  RESET_WORD(state, data) {
    state.showWord = []
    state.getWord = []
  }

}
// 비동기를 사용할 때, 또는 여러 mutations를 연달아 송출할 때
const actions = {

  getData({state, commit}) {
    if(state.getWord !== []) {
      state.getWord = []
    }
    for(var i=1; i<=Object.keys(jsonWord).length; i++) {
      commit('SET_WORD', jsonWord["day"+i])
    }
  }, // GET_ALLDATA 함수 끝

  showAll({state, commit}, data) {
    console.log(data)
    commit('SELECT_WORD', data)
    state.checked = 1
  },

  showKorean({state, commit}) {
    state.checked = 2
  },

  showSpanish({state, commit}) {
    state.checked = 3
  },

  showRandom({state, commit}, data) {
    if(state.randomWord !== []) {
      state.randomWord = []
    }
    commit('SET_RANDOMWORD', data)
    console.log(state.randomWord)
    console.log(state.showWord)
    console.log(state.getWord)
    state.randomWord[0].sort(function () {return Math.random()-Math.random()})
    state.checked = 4
  },

  resetData({state, commit}, data) {
    commit('RESET_WORD')
    for(var i=1; i<=Object.keys(jsonWord).length; i++) {
      commit('SET_WORD', jsonWord["day"+i])
    }
  }


}

export default {
  namespaced:true,
  state,
  mutations,
  actions,
  getters,

};
// spanishWord.vue

<template>
 <div>
   <button v-for="(getWord, index) in getWord" v-on:click="showAll(getWord)">day{{index+1}}</button>
   <button v-on:click="showKorean">한국어만</button>
   <button v-on:click="showSpanish">스페인어만</button>
   <button v-on:click="showRandom(showWord)">랜덤</button>
   <button v-on:click="resetData">초기화</button>

   <div v-for="showWord in showWord">
     <p v-if="checked===1"> {{showWord[0]}} : {{showWord[1]}} </p>
     <p v-else-if="checked===2"> : {{showWord[1]}} </p>
     <p v-else-if="checked===3"> {{showWord[0]}} : </p>
   </div>
   <div v-for="randomWord in randomWord[0]">
     <p v-if="checked===4"> {{randomWord[0]}} : {{randomWord[1]}}</p>
   </div>

 </div>
</template>


1. 날짜별 단어장 보기

2. 한국어 단어만 보기

3. 스페인어 단어만 보기

4. 순서 섞어서 보기

'Vue-프로젝트' 카테고리의 다른 글

vue-프로젝트 단어장(18일차)  (0) 2020.04.30
vue-프로젝트 단어장(17일차)  (0) 2020.04.28
vue-프로젝트 vuex Helper(15일차)  (0) 2020.04.24
vue-프로젝트 vuex(14일차)  (0) 2020.04.23
vue-프로젝트 (13일차)  (0) 2020.04.22
참고
vuex import 스타일 - https://kdydesign.github.io/2019/05/09/vuex-tutorial/
vuex 개념 - https://joshua1988.github.io/web-development/vuejs/vuex-actions-modules/


할일
- 스토어 폴더 파일 구조 변경


1. main.js에 store 등록했는지 확인
2. 여러개 store 사용할때 모두 module화 안하면 namespaced 인식 못함
3. createNamespacedHelpers 사용할거면 모듈에서 namespaced : true 하기



Vuex store 여러개 사용하기

1. store 폴더구조 정하기

2. 각 기능마다 state, mutations, getters, actions 모듈화해서 export 하기

// weatherData.js(날씨 데이터 모듈)

var axios = require('axios')
var cheerio = require('cheerio')

const state = {
    nowTemperature: '12', // 현재 온도
    nowWeatherCheck: '흐림', // 맑음, 흐림 체크
    todayMin: '1', // 최저기온
    todayMax: '15', // 최고기온
    todayDust: '2', // 미세먼지
    todayDDust: '2', // 초미세먼지
    // test: 'testsadasdwe',
  }
  // vue의 computed와 비슷
  const getters = {

  }
  // state를 수정할 때 사용
  const mutations = {
    SET_TEMPERATURE(state, data) {
      state.nowTemperature = data
    },
    SET_WEATHERCHECK(state, data) {
      state.nowWeatherCheck = data
    },
    SET_TODAYMIN(state, data) {
      state.todayMin = data
    },
    SET_TODAYMAX(state, data) {
      state.todayMax = data
    },
    SET_TODAYDUST(state, data) {
      state.todayDust = data
    },
    SET_TODAYDDUST(state, data) {
      state.todayDDust = data
    },
  }
  // 비동기를 사용할 때, 또는 여러 mutations를 연달아 송출할 때
  const actions = {
    getData({state, commit}, data) {
      axios.get('https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=%EB%82%A0%EC%94%A8')
      .then(res => {
        var $ = cheerio.load(res.data)
        commit('SET_TEMPERATURE', $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.main_info > div > p > span.todaytemp').text())
        commit('SET_WEATHERCHECK', $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.main_info > div > ul > li:nth-child(1) > p').text())
        commit('SET_TODAYMIN', $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.main_info > div > ul > li:nth-child(2) > span.merge > span.min').text())
        commit('SET_TODAYMAX', $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.main_info > div > ul > li:nth-child(2) > span.merge > span.max').text())
        commit('SET_TODAYDUST', $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.sub_info > div > dl > dd:nth-child(2)').text())
        commit('SET_TODAYDDUST', $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.sub_info > div > dl > dd:nth-child(4)').text())
      })
    },

  }


export default {
  namespaced:true,
  state,
  mutations,
  actions,
  getters,

};
// spanishWord.js(스페인어 데이터 모듈)

//vue의 data와 비슷
const state = {
  getWord: 'hellofe3ssss4324sㄴㄴㄴㄴ'
}
// vue의 computed와 비슷
const getters = {

}
// state를 수정할 때 사용
const mutations = {
  // [GET_WORD](state, data) {
  //   state.getWord.push(data)
  // }

}
// 비동기를 사용할 때, 또는 여러 mutations를 연달아 송출할 때
const actions = {

}

export default {
  namespaced:true,
  state,
  mutations,
  actions,
  getters,

};

3. index파일(중앙 저장소)에 모듈화 한 파일들 import하기

// index.js(중앙 저장소)

import Vue from 'vue'
import Vuex from 'vuex'

import wordStore from './wordStore/spanishWord'
import weatherStore from './weatherStore/weatherData'

Vue.use(Vuex)


export default new Vuex.Store({
    modules: {
        spanish: wordStore,
        weather: weatherStore,
    }
})

4. 해당 컴포넌트에서 import후 화면에 뿌려주기

 

기본 vuex 사용 할 때

// main.vue

import store from './store'
export default {
  name: 'main',
  store,

  components:{
    'mainTitle': mainTitle,
    'nowWeather': nowWeather,
  },

  computed:{
    nowTemperature() {
      return this.$store.state.nowTemperature
    },
    nowWeatherCheck() {
      return this.$store.state.nowWeatherCheck
    },
    todayMin() {
      return this.$store.state.todayMin
    },
    todayMax() {
      return this.$store.state.todayMax
    },
    todayDust() {
      return this.$store.state.todayDust
    },
    todayDDust() {
      return this.$store.state.todayDDust
    },
    // test() {
    //   return this.$store.state.test
    // }
  },

  data() {
    return {

    }
  },
  methods: {

  }, // methods 끝
}
</script>

mapState, mapActions 사용 할 때

// main.vue

<script>
import mainTitle from './main/mainTitle'

import {createNamespacedHelpers} from 'vuex'
const nowWeather = createNamespacedHelpers('weather')

export default {
  name: 'main',
  components:{
    mainTitle
  },
  computed:{
    ...nowWeather.mapState([
      'nowTemperature',
      'nowWeatherCheck',
      'todayMin',
      'todayMax',
      'todayDust',
      'todayDDust',
    ])
  },

  data() {
    return {

    }
  },
  methods: {
    ...nowWeather.mapActions([
      'getData'
    ])
  }, // methods 끝
  
  mounted() {
    this.getData()
  }
}
</script>

 

할일 
- vuex이용해서 현재 날씨 main컴포넌트에서 사용하기
- 단어 시험장 만들기



1. Object.keys(words).length - 객체의 키 길이를 구하고 싶을때 사용
2. 변수.push(값) - 변수를 [] 빈배열로 초기화 해야됌 아니면 에러뜸
3. import store from '??' - 선언 store말고 다른 이름쓰면 vuex 사용안됌

1. vuex이용해서 현재 날씨 main컴포넌트에서 사용하기

1. store에서 변수 만들기

2. 하위컴포넌트에서 store 변수에 현재 날씨 데이터 넣기

3. store에서 바뀐 데이터 상위 컴포넌트에 갱신하기

// store.js

import Vue from 'vue';
import Vuex from 'vuex';

export const SET_TEMPERATURE = 'SET_TEMPERATURE'
export const SET_WEATHERCHECK = 'SET_WEATHERCHECK'
export const SET_TODAYMIN = 'SET_TODAYMIN'
export const SET_TODAYMAX = 'SET_TODAYMAX'
export const SET_TODAYDUST = 'SET_TODAYDUST'
export const SET_TODAYDDUST = 'SET_TODAYDDUST'

Vue.use(Vuex);
export default new Vuex.Store({
  //vue의 data와 비슷
  state: {
    nowTemperature: '', // 현재 온도
    nowWeatherCheck: '', // 맑음, 흐림 체크
    todayMin: '', // 최저기온
    todayMax: '', // 최고기온
    todayDust: '', // 미세먼지
    todayDDust: '', // 초미세먼지
  },
  // vue의 computed와 비슷
  getters: {

  },
  // state를 수정할 때 사용
  mutations:{
    [SET_TEMPERATURE](state, data) {
      state.nowTemperature = data
    },
    [SET_WEATHERCHECK](state, data) {
      state.nowWeatherCheck = data
    },
    [SET_TODAYMIN](state, data) {
      state.todayMin = data
    },
    [SET_TODAYMAX](state, data) {
      state.todayMax = data
    },
    [SET_TODAYDUST](state, data) {
      state.todayDust = data
    },
    [SET_TODAYDDUST](state, data) {
      state.todayDDust = data
    },
  },
  // 비동기를 사용할 때, 또는 여러 mutations를 연달아 송출할 때
  actions: {

  },
})
// nowWeather.vue(하위 컴포넌트)

<script>
import store, { SET_TEMPERATURE,
               SET_WEATHERCHECK,
               SET_TODAYMIN,
               SET_TODAYMAX,
               SET_TODAYDUST,
               SET_TODAYDDUST } from '../store'

var axios = require('axios')
var cheerio = require('cheerio');

export default {
  store,
  data() {
    return {
      loaded : false
    }
  },

  methods:{
    getData() {
      axios.get('https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=%EB%82%A0%EC%94%A8')
      .then(res => {
        var $ = cheerio.load(res.data)
        this.loaded = true

        this.$store.commit(SET_TEMPERATURE, $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.main_info > div > p > span.todaytemp').text())
        this.$store.commit(SET_WEATHERCHECK, $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.main_info > div > ul > li:nth-child(1) > p').text())
        this.$store.commit(SET_TODAYMIN, $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.main_info > div > ul > li:nth-child(2) > span.merge > span.min').text())
        this.$store.commit(SET_TODAYMAX, $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.main_info > div > ul > li:nth-child(2) > span.merge > span.max').text())
        this.$store.commit(SET_TODAYDUST, $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.sub_info > div > dl > dd:nth-child(2)').text())
        this.$store.commit(SET_TODAYDDUST, $('#main_pack > div.sc.cs_weather._weather > div:nth-child(2) > div.weather_box > div.weather_area._mainArea > div.today_area._mainTabContent > div.sub_info > div > dl > dd:nth-child(4)').text())
      })
    }
  },

  mounted() {
    this.getData()
  }
}
</script>

<style scoped>
</style>
// main.vue(최상위 컴포넌트)



<script>
import mainTitle from './main/mainTitle'
import nowWeather from './weather/nowWeather'

import store from './store'
export default {
  name: 'main',
  store,

  components:{
    'mainTitle': mainTitle,
    'nowWeather': nowWeather,
  },

  computed:{
    nowTemperature() {
      return this.$store.state.nowTemperature
    },
    nowWeatherCheck() {
      return this.$store.state.nowWeatherCheck
    },
    todayMin() {
      return this.$store.state.todayMin
    },
    todayMax() {
      return this.$store.state.todayMax
    },
    todayDust() {
      return this.$store.state.todayDust
    },
    todayDDust() {
      return this.$store.state.todayDDust
    },
  },

  data() {
    return {

    }
  },
  methods: {

  }, // methods 끝
}
</script>


2. Vuex이용해서 단어 시험장 만들기

파일 구조

상위 컴포넌트 - 하위 컴포넌트에서 변경한 데이터 html, css이용해서 꾸미기 

하위 컴포넌트들 - 단어 관련된 데이터 가공(모든 단어, 스페인어 가리기, 한국어 가리기, 무작위 가리기, 등등) 

store - 단어 관련된 데이터 저장 

 

// wordStore.js

import Vue from 'vue';
import Vuex from 'vuex';

export const GET_WORD = 'GET_WORD'


Vue.use(Vuex);
export default new Vuex.Store({
  //vue의 data와 비슷
  state: {
    getWord: [],

  },
  // vue의 computed와 비슷
  getters: {

  },
  // state를 수정할 때 사용
  mutations:{
    [GET_WORD](state, data) {
      state.getWord.push(data)
    },

  },
  // 비동기를 사용할 때, 또는 여러 mutations를 연달아 송출할 때
  actions: {

  },
})
// spanishWord.vue(최상위 컴포넌트)

<template>
 <div>
   <get-word></get-word>
   <button v-for="(word, index) in word" v-on:click="showAll(word)">day{{index+1}}</button>
   <div v-for="showWord in showWord">
     <p>{{showWord[0]}} : {{showWord[1]}}</p>
   </div>
 </div>
</template>

<script>
import store from './spanishWord/wordStore'
import getWord from './spanishWord/getWord'
export default {
  store,
  components: {
    'getWord': getWord,
  },
  data() {
    return {
      showWord: [],
      loaded: false,
    }
  },
  computed: {
    word() {
      return this.$store.state.getWord
    }
  },
  methods: {
    showAll(word) {
      this.loaded = true
      this.showWord = word
    }

  }, // methods 끝
  mounted() {

  }, //mounted 끝
}
</script>

<style scoped>
</style>
// getWord.vue(하위 컴포넌트)

<script>
import store ,{GET_WORD} from './wordStore'
import words from '../../json/word.json'

export default {
  store,
  methods: {
    getAllData() {
      // console.log(Object.keys(words).length)
      for(var i=1; i<=Object.keys(words).length; i++){
        this.$store.commit(GET_WORD, words["day"+i])
      }
    }, // getAllData 함수 끝
  }, // methods 끝
  mounted() {
    this.getAllData()
  }
}
</script>

<style scoped>
</style>
오늘 할일
- 코인이름 클릭시 해당 코인 데이터로 차트 갱신
- 현재 날씨 mainTitle 왼쪽에 vuex이용해서 넣기

- 코인이름 클릭시 해당 코인 데이터로 차트 갱신

    drawChart(eng, kor) {
      if(this.total != []) {
        this.total = []
        this.find = false
      }
      axios.get('https://api.upbit.com/v1/candles/minutes/60?market='+eng+'&count=70')
      .then(res => {
        this.coinName = kor
        this.find = true
        for(var i=0; i<res.data.length; i++){
          this.total.push([res.data[i].candle_date_time_kst, res.data[i].opening_price, res.data[i].high_price, res.data[i].low_price, res.data[i].trade_price])
        }
      })
    }, // drawChart 끝

- 조건문에서 코인데이터 값이 들어있을경우 빈배열로 초기화

- find변수를 false로 바꿔준다(그렇지 않으면 데이터값은 들어가지만 차트가 갱신이 안됌) 

참고
https://apexcharts.com/docs/chart-types/candlestick/

내일 할일
- 코인 클릭시 이전에 만든 차트 현재 클릭한 코인으로 데이터 갱신
- 초기 가격 기준 고가, 저가% 구하기
- 마우스 커서 올리면 시간 나오게하기
- 드래그로 캔들 움직이게하기
-  

ApexChart이용해서 비트코인 차트 만들기

1. 해당 코인 클릭시 60분간격 데이터 70개 가져오기

// bitcoinFindData.vue - javascript

     drawChart(eng, kor) {
      axios.get('https://api.upbit.com/v1/candles/minutes/60?market='+eng+'&count=70')
      .then(res => {
        console.log(res.data)
        this.coinName = kor
        this.find = true
        for(var i=0; i<res.data.length; i++){
          this.total.push([res.data[i].candle_date_time_kst, res.data[i].opening_price, res.data[i].high_price, res.data[i].low_price, res.data[i].trade_price])
        }
      })
    }, // drawChart 끝

- 해당 코인 클릭시 drawChart함수에서 eng인자로 값 받아와서 넣어주기

- total 빈배열 필요한 데이터 push 하기

- this.find =  true 값으로 변경하기(안하면 차트에 데이터값이 업데이트 안됌)

// bitcoinFindData.vue - html

<bitcoin-chart v-bind:coinName="coinName" v-bind:total="total" v-if="find===true" ></bitcoin-chart>

- props데이터 <bitcoin-chart>하위 컴포넌트에 넘겨주기

 

2. ApexChart.js 사용해서 차트 그리기

// bitcoinChart.vue

<template>
  <div>
    <apexchart type="candlestick" height="350" :options="chartOptions" :series="series"></apexchart>
  </div>

</template>

<script>
import VueApexCharts from 'vue-apexcharts'
export default {
  name: 'Chart',
  props:{
    total:{
      type: Array,
    },
    coinName:{
      type: String,
    },
  },
  components: {
    apexchart: VueApexCharts,
  },
  data() {
    return {
      series:
      [{
        data: this.total
      }],
      
      chartOptions: {
        chart: {
          type: 'candlestick',
          height: 350
        },
        title: {
          text: this.coinName,
          align: 'left'
        },
        xaxis: {
          type: 'datetime'
        },
        yaxis: {
          tooltip: {
            enabled: true
          }
        },
        fill: {
          colors: ['red', 'blue']
        },
        plotOptions: {
          candlestick: {
            // colors: {
            //   upward: 'red',
            //   downward: 'blue'
            // },
            wick: {
              useFillColor:false,
            }
          }
        }
      },

    }
  },

}
</script>

<style scoped>
</style>

- 상위 컴포넌트에서 전달받은 코인 시세와 코인 이름 data 저장

 

 

 

 

+ Recent posts