Nuxt 3でタスクリストを作ってみる

更新:2025-03-18
JavaScript
概要
Vue.jsのフレームワーク「Nuxt.js」を使用してタスクリストを作成する。
プロジェクトの作成
npm create nuxt@latest
久しぶりにcreateを実行したら、最初の段階で公式のモジュールを選択できるようになっていたので、@nuxt/eslint
と@nuxt/icon
を入れておいた。
開発環境の整備
パスエイリアス
export default defineNuxtConfig({ compatibilityDate: '2024-11-01', devtools: { enabled: true }, modules: ['@nuxt/eslint', '@nuxt/icon'], rootDir: 'src'})
モジュールの追加
npm i dexie nuxt-lodash vue-draggable-next vue-toast-notification
モジュール名 | 簡易説明 |
---|---|
dexie | IndexedDBを扱いやすくするライブラリ。 |
nuxt-lodash | いろいろ便利な関数があるライブラリ。 |
vue-draggable-next | ドラッグアンドドロップ用のライブラリ。 |
vue-toast-notification | トースト用のライブラリ。 |
npm i -D destyle.css sass
モジュール名 | 簡易説明 |
---|---|
destyle.css | リセットCSS。 |
sass | Sassによるスタイリング。 |
いろいろメモ
データの永続化
クライアントサイドで完結させたかったので、IndexedDBを使用した。ブラウザを変えたりサイトのデータを消せば消えてしまうので、半永続化ぐらいの感覚かもしれない。
プロトタイプ実装時は、以下の記事を参考にした気がする。
https://qiita.com/yamayamasan/items/a4297e724b86f4a00fd2
入力時の自動保存
@input
で入力のたびにデータを更新すると表示内容とデータに差異が出そうなので、lodash
のdebounce
を使用して「入力が1秒止まったら」保存するようにした。
export default defineNuxtConfig({ ... modules: ['@nuxt/eslint', '@nuxt/icon'], modules: ['@nuxt/eslint', '@nuxt/icon', 'nuxt-lodash'], lodash: { prefix: 'lodash', }, ...})
const updateText = lodashDebounce((text: string) => { // 保存する処理をここに書く}, 1000);
トースト
まえZennに書いていたものがあった。
https://zenn.dev/namakurajin/articles/177b28414169a2
成果物
続く...かもね