해당 라이브러리는 말이 필요 없다.

적용 방법은 아래와 같으며, 간단하게 날짜에 관한 문제를 거의 모든걸 해결해준다.

document.addEventListener("DOMContentLoaded", function(){
	var nowMoment = moment(new Data());
	nowMoment.format('YYYY-MM-DD hh:mm:ss');       // 2020-06-09 16:43:22

	// Add day 
	nowMoment.add(1, 'days').format('YYYY-MM-DD');   // 2020-06-10
  // Add Month 
	nowMoment.add(1, 'months').format('YYYY-MM-DD');  // 2020-07-10
  // Add Year
	nowMoment.add(1, 'years').format('YYYY-MM-DD');  // 2021-07-10

  // first Month Date
	nowMoment.startOf('month').format('YYYY-MM-DD');  // 2021-07-01
  // end Month Date
	nowMoment.endOf('month').format('YYYY-MM-DD');  // 2021-07-31

});

 

 

IDE 도구는 Visual Studio Code 로 작업 진행하고 IDE에 사용 되는 Vue 관련 플로그 인은 별도 설명은 생략 한다.

1. Vue Js 앱 생성 과정

# vue-cli 설치
$ npm install -g @vue/cli
# vue 앱 생성
$ vue create simple-board
$ cd simple-board
# vuetify 추가 설치
$ vue add vuetify
# 설치 진행중 질문 사항
✔  Successfully installed plugin: vue-cli-plugin-vuetify

? Choose a preset: Configure (advanced)
? Use a pre-made template? (will replace App.vue and HelloWorld.vue) Yes
? Use custom theme? No
? Use custom properties (CSS variables)? No
? Select icon font Material Icons
? Use fonts as a dependency (for Electron or offline)? Yes
? Use a-la-carte components? No
? Use babel/polyfill? Yes
? Select locale Korean
# 기본 vueJS 앱 서버 실행
$ npm run serve
# 성공시 아래와 같은 메시지 확인과 주소 접근시 페이지 확인 가능.
DONE  Compiled successfully in 5252ms                                                                                                                                                       10:45:31 AM

  App running at:
  - Local:   http://localhost:8080/
  - Network: http://192.168.1.179:8080/

  Note that the development build is not optimized.
  To create a production build, run npm run build.

2. 앱 생성 후 기본 주요 디렉토리 구조

├─node_modules             
├─public    
├─src
│  ├─App.vue
│  ├─main.js 
│  ├─assets
│  ├─components
│  │  └─HelloWorld.vue
│  └─plugins
│	  └─vuetify.js
├─babel.config.js
├─package-lock.json
├─package.json
└─README.md

3. Router 설치

# vuex 및 vue-router 설치
$ npm install --save-dev vue-router vuex

4. Router 적용

/* ## -- src/main.js 변경 사항 */
import Vue from 'vue'
import App from './App.vue'
import vuetify from './plugins/vuetify'
import router from './router'
import '@babel/polyfill'
import 'roboto-fontface/css/roboto/roboto-fontface.css'
import 'material-design-icons-iconfont/dist/material-design-icons.css'

Vue.config.productionTip = false

new Vue({
  vuetify,
  router,
  render: h => h(App)
}).$mount('#app')


/* ## -- src/router 폴더 생성 후 index.js 내용 */
import Vue from 'vue'
import Router from 'vue-router'
import BoardList from '@/components/BoardList'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'BoardList',
      component: BoardList
    }
  ]
})

*/ ## -- src/App.vue 변경 내용 */
<template>
  <div id="app">
    <v-app-bar>
        Simple Board
    </v-app-bar>
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App'
};
</script>

5. 게시판 목록 / 상세 / 작성 라우터 설정

/* axios 설치 */
$ npm install --save-dev axios

/* ## src/router/index.js 내용 변경 */
import Vue from 'vue'
import Router from 'vue-router'
import BoardList from '@/components/BoardList'
import BoardView from '@/components/BoardView'
import BoardWriter from '@/components/BoardWriter'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'BoardList',
      component: BoardList
    },
    {
      path: '/view/:seq',
      name: 'BoardView',
      component: BoardView
    },
    {
      path: '/writer',
      name: 'BoardWriter',
      component: BoardWriter
    }
  ]
})

6. 각 게시판 목록 / 상세 / 작성 컨포넌트 파일 생성 및 내용

/* ## BoardList.vue 내용 */
<template>
  <v-container>
    <v-data-table
      :headers="headers"
      :items="desserts"
      :items-per-page="5"
      class="elevation-1"
      @click:row="rowClick"
    >
    </v-data-table>
    <v-row>
      <v-btn outlined color="blue" @click="writeClick" > 작성 </v-btn>
    </v-row>
  </v-container>
</template>

<script>
import axios from 'axios'

export default {
  name: 'BoardList',
  created() {
    this.fetch()
  },
  methods: {
    fetch() {
      console.log('fetch list')
      axios.get('http://localhost:8000/api/board/list')
      .then((response) => {
        console.log(response)
      })
      .catch((error) => {
        console.log(error)
      })
    },
    writeClick() {
      this.$router.push('/writer')
    },
    rowClick(item) {
      this.$router.push('/view/' + item.seq)
    }
  },
  data () {
      return {
        headers: [
          {
            text: 'Number',
            align: 'left',
            sortable: false,
            value: 'number',
          },
          { text: 'Title', value: 'title' },
          { text: 'Reg Date', value: 'regDt' }
        ],
        desserts: [],
      }
    }
};
</script>

/* ## BoardWrite.vue 파일 내용 */
<template>
  <v-form>
    <v-container>
      <v-row>
        제목
      </v-row>
      <v-row>
        <v-text-field
          :counter="50"
          label="제목"
          name="title"
          required
          v-model="title"
          maxlength="50"
        ></v-text-field>
      </v-row>
      <v-row>
        내용 
      </v-row>
      <v-row>
        <v-textarea
          filled
          name="context"
          hint="내용을 입력해주세요."
          v-model="context"
          :counter="1000"
          maxlength="1000"
        ></v-textarea>
      </v-row>
      <v-row>
        <v-btn block outlined color="blue" @click="writeClick"> 등록 </v-btn>
      </v-row>
    </v-container>
  </v-form>    
</template>

<script>
import axios from 'axios'

export default {
  name: 'BoardWriter',
  methods: {
    writeClick() {
      if(this.$route.params.seq) {
        axios.put('http://localhost:8000/api/board', this.$data)
        .then((response) => {
          console.log(response)
          this.$router.push('/')
        })
        .catch((error) => {
          console.log(error)
        })
      } else {
        this.$data.regDt = this.getNowDate()
        this.$data.uptDt = this.getNowDate()
        axios.post('http://localhost:8000/api/board', this.$data)
        .then((response) => {
          console.log(response)
          this.$router.push('/')
        })
        .catch((error) => {
          console.log(error)
        })
      }
    },
    getNowDate() {
      var nowDate = new Date()
      var year = nowDate.getFullYear().toString()
      var month = (nowDate.getMonth() + 1).toString()
      var day = nowDate.getDate().toString()

      return year + "-" + (month[1] ? month : "0" + month[0]) + "-" + (day[1] ? day : "0" + day[0])
    }
  },
  data () {
    return {
      title : '',
      context: '',
      uptDt: '',
      regDt: ''
    }
  }
}
</script>


/* ## BoardView.vue 파일 내용 */
<template>
  <v-form>
    <v-container>
      <v-row>
        제목
      </v-row>
      <v-row>
        {{ title }}
      </v-row>
      <v-row>
        내용 
      </v-row>
      <v-row>
        {{ context }}
      </v-row>
      <v-row>
        <v-btn block outlined color="blue" @click="listClick"> 목록 </v-btn>
      </v-row>
    </v-container>
  </v-form>    
</template>

<script>
import axios from 'axios'

export default {
  name: 'BoardView',
  created() {
    this.fetch()
  },
  methods: {
    fetch() {
      axios.get('http://localhost:8000/api/board/' + this.$$router.params.seq)
      .then((response) => {
        console.log(response)
      })
      .catch((error) => {
        console.log(error)
      })
    },
    listClick() {
      this.$router.push('/')
    },
    deleteClick() {
      if(this.$data.seq) {
        axios.delete('http://localhost:8000/api/board/' + this.$data.seq)
        .then((response) => {
          console.log(response)
          this.$router.push('/')
        })
        .catch((error) => {
          console.log(error)
        })
      }
    }
  },
  data () {
    return {
      title : "",
      context: ""
    }
  }
}
</script>

'Javascript' 카테고리의 다른 글

날짜 라이브러리 moment JS  (1) 2020.06.10
Vue Js 설치  (0) 2019.10.01
자바스크립트(Javascript)에서 GET 파라메타 함수  (0) 2018.09.10
jQuery 웹 페이지 로드 테스트  (0) 2018.09.06
jQuery Template 사용.  (0) 2018.09.04

설치 목록

 

1. 설치 Vue-cli

npm install -g vue-cli

2. vueJS [webpack]으로 프로젝트 생성

vue init webpack project

3. 테스트 컴파일

vue run build

4. [프로젝트/dist/]에서 컴파일하여 추출된 소스 확인 가능.

5. VueJs 제공되는 서버 구동 하기

npm run dev

VueJs Welcome Page

 

가끔씩 필요할 때가 있다. 일일이 Split 해서 가져오는 방법도 있겠지만 특정 다수의 GET 파라메타를 가져올 때가 사용하기 편한 것 같다.

소스는 아래와 같다.


'Javascript' 카테고리의 다른 글

날짜 라이브러리 moment JS  (1) 2020.06.10
Front-end 간단한 게시판 구현 ( VueJs + Vuetify)  (0) 2020.01.30
Vue Js 설치  (0) 2019.10.01
jQuery 웹 페이지 로드 테스트  (0) 2018.09.06
jQuery Template 사용.  (0) 2018.09.04

jQuery 사용 시에 웹 페이지에 로드 되는 순서가 궁금해서 테스트를 해보았다. 


$(window).load(function (){

});


위의 소스가 제일 먼저 빠르게 호출이 되면서 세팅이 된다. 

이후 아래 소스는 동일한 선상에서 호출이 된다.

$(function (){

});


OR 


$(document).ready(function (){

});


+ Recent posts