Buefy의 Pagination을 이용해서 Nuxt에서 pagination을 구현해보려고 한다.

 

<template>
    <section>
        <b-pagination
            :total="200" <!-- 전체 아이템 갯수 -->
            v-model="current"
            :per-page="10"> <!-- 페이지당 아이템 갯수 -->

            <template #default="props">
                <b-pagination-button
                    :page="props.page"
                    :id="`page${props.page.number}`"
                    tag="router-link"
                    :to="`/documentation/pagination#page${props.page.number}`"> <!-- hash를 사용한 url -->
                    {{ props.page.number }}
                </b-pagination-button>
            </template>


            <template #previous="props">
                <b-pagination-button
                    :page="props.page"
                    tag="router-link"
                    :to="`/documentation/pagination#page${props.page.number}`">
                    Previous
                </b-pagination-button>
            </template>

            <template #next="props">
                <b-pagination-button
                    :page="props.page"
                    tag="router-link"
                    :to="`/documentation/pagination#page${props.page.number}`">
                    Next
                </b-pagination-button>
            </template>

        </b-pagination>
    </section>
</template>

<script>
    export default {
        data() {
            return {
                current: 10,
            }
        },
        watch: {
            $route: {
                immediate: true,
                handler(newVal, oldVal) {
                    if (newVal.hash) {
                        this.current = parseInt(newVal.hash.replace(/#page/g, '')) // url에서 #page 를 ''로 바꾸고 남은 숫자 (페이지 숫자를 가져온다.)
                    }
                },
            },
        }
    }
</script>

참고)

 

Replace()에서 치환을 당담하는것은, 정규식의 g 부분이다. 해당위치에 오는 문자에 따라서

g : 문자열 내의 모든 패턴 체크

i : 대소문자를 구별하지 않음

m : 여러줄에 걸쳐서 체크

 

 

v-for="(item, idx) in posts.slice(sliceStart, sliceEnd)"

slice를 통해 데이터를 자른다음에 보여주면 된다. 페이지네이션이 되면 hash값으로 숫자를 얻을 수 있기 때문에 이를 계산하는 함수로 데이터를 처리해주면 된다. 

 

ex) 만약에 페이지당 10개씩 데이터를 보여주게 된다면 sliceStart는 0이되고 sliceEnd는 10이 된다. 이후에 페이지 네이션이 될때마다 계산을 해주면 되는데 

 

sliceEnd = 페이지네이션 번호 * 페이지당 보여줄 데이터 수

sliceStart = sliceEnd - 페이지당 보여줄 데이터 수

 

이런 함수를 만들어서 계산하면 된다.

'Front-End > Vue & Nuxt' 카테고리의 다른 글

Nuxt.js Lottie 사용하기  (0) 2022.02.27
Eslint Babel정리  (0) 2022.02.27
Nuxt.js 유용한 모듈 정리  (0) 2022.02.26
Nuxt.js SCSS 사용  (0) 2022.02.26
Nuxt.js Transition  (0) 2022.02.26

nuxt-highlight.js

 

https://github.com/Llang8/nuxt-highlightjs

 

GitHub - Llang8/nuxt-highlightjs: Highlight.js syntax highlighting for Nuxt.js

Highlight.js syntax highlighting for Nuxt.js. Contribute to Llang8/nuxt-highlightjs development by creating an account on GitHub.

github.com

pre태그와 code 태그를 사용하여 각 프로그래밍 언어를 하이라이트해주는 모듈이다. 

 

 

vue-dompurify-html

 

https://github.com/LeSuisse/vue-dompurify-html

 

GitHub - LeSuisse/vue-dompurify-html: Safe replacement for the v-html directive

Safe replacement for the v-html directive. Contribute to LeSuisse/vue-dompurify-html development by creating an account on GitHub.

github.com

Editor로 작성된 데이터는 v-html을 통해 파싱해서 보여줘야한다. 다만 v-html은 xss공격에 취약해서 eslint 경고가 뜬다. 그럴경우 위 모듈을 사용해서 작성하면 된다.

 

 

moment-module

 

https://github.com/nuxt-community/moment-module

 

GitHub - nuxt-community/moment-module: Efficient Moment.js integration for Nuxt

Efficient Moment.js integration for Nuxt. Contribute to nuxt-community/moment-module development by creating an account on GitHub.

github.com

new Date() 시간 객체를 지역 설정에 맞게 표시해준다. 

 

 

 

'Front-End > Vue & Nuxt' 카테고리의 다른 글

Eslint Babel정리  (0) 2022.02.27
Nuxt.js Buefy Pagination  (0) 2022.02.26
Nuxt.js SCSS 사용  (0) 2022.02.26
Nuxt.js Transition  (0) 2022.02.26
Nuxt 라이브러리 적용  (0) 2022.02.15

Nuxt.js에서 SCSS를 사용하는 방법이다. 

 

 

https://nuxtjs.org/docs/features/configuration/

 

Configuration

By default, Nuxt is configured to cover most use cases. This default configuration can be overwritten with the nuxt.config.js file.

nuxtjs.org

 

 

SASS Loader 설치

yarn add --dev sass sass-loader@10
npm install --save-dev sass sass-loader@10

 

 

nuxt.config.js 정의

export default {
  css: [
    // Load a Node.js module directly (here it's a Sass file)
    'bulma',
    // CSS file in the project
    '~/assets/css/main.css',
    // SCSS file in the project
    '~/assets/css/main.scss'
  ]
}

 

 

추가)

 

SCSS에서 Variable을 사용하고 싶을 때가 있을 것이다. 그럴경우 추가 Module을 설치해야한다. 

https://github.com/nuxt-community/style-resources-module

 

GitHub - nuxt-community/style-resources-module: Nobody likes extra @import statements!

Nobody likes extra @import statements! Contribute to nuxt-community/style-resources-module development by creating an account on GitHub.

github.com

 

Style Resource라는 모듈이다. 

 

yarn add -D @nuxtjs/style-resources

 

nuxt.config.js

export default {
  buildModules: ['@nuxtjs/style-resources'],
  styleResources: {
    scss: [
      './assets/vars/*.scss',
      './assets/abstracts/_mixins.scss' // use underscore "_" & also file extension ".scss"
      ]
  }
}

'Front-End > Vue & Nuxt' 카테고리의 다른 글

Nuxt.js Buefy Pagination  (0) 2022.02.26
Nuxt.js 유용한 모듈 정리  (0) 2022.02.26
Nuxt.js Transition  (0) 2022.02.26
Nuxt 라이브러리 적용  (0) 2022.02.15
Vercel 배포  (0) 2022.02.10

https://vuejs.org/guide/built-ins/transition.html#css-based-transitions

 

Transition | Vue.js

 

vuejs.org

https://nuxtjs.org/docs/features/transitions

 

Transitions

Nuxt uses the transition component to let you create amazing transitions/animations between your routes.

nuxtjs.org

 

Nuxt에서 transition을 사용하는 방법에 대해서 알아보자.

 

export default {
  // Can be a String
  transition: ''
  // Or an Object
  transition: {}
  // or a Function
  transition (to, from) {}
}

 

 

지역 사용

 

pages/index.vue

export default {
  transition: 'home'
}

<style>
  .home-enter-active, .home-leave-active { transition: opacity .5s; }
  .home-enter, .home-leave-active { opacity: 0; }
</style>

transition의 name을 home으로 설정했기 때문에 .home이 된다. test로 설정하면 .test이런식으로 설정이 된다.

 

 

전역 사용

 

main.css

 

page변경 시 설정

.page-enter-active,
.page-leave-active {
  transition: opacity 0.5s;
}
.page-enter,
.page-leave-to {
  opacity: 0;
}
export default {
  css: ['~/assets/main.css']
}

 

layout변경 시 설정

.layout-enter-active,
.layout-leave-active {
  transition: opacity 0.5s;
}
.layout-enter,
.layout-leave-active {
  opacity: 0;
}

 

만약에 default 설정을 바꾸고 싶다면 다음처럼 설정 하면 된다.

 

nuxt.config.js

// Pages

export default {
  pageTransition: 'my-page'
  // or
  pageTransition: {
    name: 'my-page',
    mode: 'out-in',
    beforeEnter (el) {
      console.log('Before enter...');
    }
  }
}


// Layouts

export default {
  layoutTransition: 'my-layouts'
  // or
  layoutTransition: {
    name: 'my-layouts',
    mode: 'out-in'
  }
}

 

 

추가)

 

mode : out-in과 in-out이 있는데 기본 값은 out-in이다. in-out으로도 설정할 수 있다. transition이 안에서 밖으로 효과가 나타날것인지 아니면 반대로 나타날 것인지 설정해준다.

 

:name="transitionName" 동적으로 transition을 설정하여 사용할 수도 있다.

 

 

 

'Front-End > Vue & Nuxt' 카테고리의 다른 글

Nuxt.js 유용한 모듈 정리  (0) 2022.02.26
Nuxt.js SCSS 사용  (0) 2022.02.26
Nuxt 라이브러리 적용  (0) 2022.02.15
Vercel 배포  (0) 2022.02.10
Nuxt-2 ezst nuxt.config.js  (0) 2022.01.30

Nuxt에서 Brython을 적용하는 방법에 대해서 기술해본다. 

정확하게는 js 라이브러리 파일을 Nuxt에다 적용하는 방법이다. 

 

참고문서 

 

https://develop365.gitlab.io/nuxtjs-0.10.7-doc/ko/guide/plugins/

 

플러그인 - Nuxt.js

모든 Vue 인스턴스의 라이프사이클에서 클라이언트사이드와 서버사이드 모두 호출되는 메소드 는 beforeCreate와 created 뿐입니다. 다른 메소드들은 모두 클라이언트 사이드에서만 호출됨을 명심하

develop365.gitlab.io

 

https://stackoverflow.com/questions/63190124/how-can-solve-the-error-babel-maximum-size-500kb-issue-in-server

 

How can solve the ERROR [BABEL] maximum size 500KB issue in server?

I am using NUXTJS application for an SSR page, but i am getting an error of bootstrap-vue icon size issue. The file is hosted in AWS server and this will be the error The code generator has deoptim...

stackoverflow.com

 

First,

static/vendor/brython-runnder.bundle.js에 파일 저장

 

1. vendor를 통한 적용방법 (라이브러리 용량이 적을경우)

 

  build: {
    vendor: ['vue-brython'],
    babel: {
      compact: true,
    },
  },

 

 

 

2. plugins 파일 생성 (라이브러리 용량이 크고 여러 곳에서 사용할 경우)

 

plugins/vue-brython.js

 

import Vue from 'vue'
import BrythonRunner from 'static/vendor/brython-runner.bundle'

Vue.use(BrythonRunner)
  plugins: [
    { src: '~/plugins/vue-brython', ssr: false },
  ],
  
  build: {
    babel: {
      compact: true,
    },
  },

 

 

3. 직접 적용 (한 곳에서만 사용할 경우)

 

<script>
import {BrythonRunner} from 'static/vendor/brython-runner.bundle';
</script>

다만 직접 가져오는 방식은 관리와 window 객체를 사용한 라이브러리일 경우 오류의 문제점이 발생한다.

 

 

 

Settings

 

코드 규칙을 위한 eslint는 까다롭기 때문에 형식에 조금이라도 벗어나면 발생하면 바로 오류를 발생시킨다. 

이미 plugins이나 vendor를 통해 전역으로 설정한 라이브러리라도 component나 page에 정의가 안되어 있을경우 오류를 발생시킨다.

 

 

.eslintrc.js

  globals: {
    BrythonRunner: true,
  },

위와 같이 BrythonRunner를 전역으로 설정해줘야한다. 

 

또한, 라이브러리에 eslint 적용을 제외하기 위해 .eslintignore 파일을 만든다. 

 

static/vendor/brython-runner.bundle.js

'Front-End > Vue & Nuxt' 카테고리의 다른 글

Nuxt.js SCSS 사용  (0) 2022.02.26
Nuxt.js Transition  (0) 2022.02.26
Vercel 배포  (0) 2022.02.10
Nuxt-2 ezst nuxt.config.js  (0) 2022.01.30
Hide Navbar on Scroll Down in Vue  (0) 2022.01.05

https://vercel.com/

 

Develop. Preview. Ship. For the best frontend teams – Vercel

Deploy web projects with the best frontend developer experience and highest end-user performance.

vercel.com

 

Vercel로 간단하게 Nuxt 프로젝트를 배포하는 방법에 대해서 정리

 

1. Vercel 설치

 

 

yarn global add vercel

npm i -g vercel

 

 

2. 환경 변수 설정

 

 

yarn : C:\Users\i\AppData\Local\Yarn\bin 추가

 

vercel -v

 

 

3. now.json 추가

 

프로젝트에 다음파일을 만들어 내용을 추가해주면 된다.

{
  "version": 2,
  "builds": [
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {}
    }
  ]
}

 

 

4. 배포

 

vercel .

 

 

5. 환경변수 설정

 

https://vercel.com/docs/concepts/projects/environment-variables

'Front-End > Vue & Nuxt' 카테고리의 다른 글

Nuxt.js Transition  (0) 2022.02.26
Nuxt 라이브러리 적용  (0) 2022.02.15
Nuxt-2 ezst nuxt.config.js  (0) 2022.01.30
Hide Navbar on Scroll Down in Vue  (0) 2022.01.05
Nuxt.js Async, Fetch  (0) 2022.01.05

+ Recent posts