Nuxt.js timeline-vuejsを使用してタイムラインを表示する
環境
node v12.13.0
npm 6.13.7
Nuxt.js v2.11.0
1.nuxtappという名前でプロジェクトを作成します。
npx create-nuxt-app nuxtapp
2,外部IPを許可します
作成したプロジェクト配下にあるpackage.jsonに下記を追加します。
"config": {
"nuxt": {
"host": "0.0.0.0",
"port": "3000"
}
},
3.timeline-vuejsをインストールします
## 作成したプロジェクトに移動
cd nuxtapp
## インストール
yarn add timeline-vuejs
4.plugins配下にplugin.jsを作成します
import Vue from 'vue'
import '../node_modules/timeline-vuejs/dist/timeline-vuejs.css'
import Timeline from 'timeline-vuejs'
Vue.component('Timeline', Timeline)
プロジェクト配下にnuxt.config.jsに下記のコードを追加します。
plugins: [
{
src: '@/plugins/plugin',
mode: 'client'
}
],
5.pages配下にあるindex.vueを編集します
<template>
<div class="container">
<div>
<logo />
<div>
<Timeline
:timeline-items="timelineItems"
:message-when-no-items="messageWhenNoItems"
colorDots="#3CB70D"
order="desc"
/>
</div>
</div>
</div>
</template>
<script>
import Logo from '~/components/Logo.vue'
export default {
name: 'Nuxttest',
components: {
Logo
},
data () {
return {
messageWhenNoItems: '項目が存在しません',
timelineItems: [
{
from: new Date(2024, 11),
title: 'title11',
description:
'hhhhhhhhh'
},
{
from: new Date(2021, 1),
title: 'title2',
description:
'uuuuuuuu'
}
]
}
}
}
</script>
<style>
.container {
display: flex;
justify-content: center;
}
</style>
Nuxt.jsを起動します
yarn dev
ブラウザから http://プライベートIP:3000にアクセスします