Skip to content

Commit

Permalink
feat: 演習 debounce #15
Browse files Browse the repository at this point in the history
  • Loading branch information
knokmki612 committed Feb 5, 2022
1 parent 901cb6d commit 1dd9fbb
Show file tree
Hide file tree
Showing 22 changed files with 247 additions and 0 deletions.
5 changes: 5 additions & 0 deletions practice-debounce-answer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
7 changes: 7 additions & 0 deletions practice-debounce-answer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Vue 3 + Vite

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)
13 changes: 13 additions & 0 deletions practice-debounce-answer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions practice-debounce-answer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "vue-3-practices-debounce-answer",
"description": "演習 debounce 解答",
"version": "1.0.0",
"author": "tuqulore Inc.",
"bugs": {
"url": "https://github.com/tuqulore/vue-3-practices/issues"
},
"dependencies": {
"vue": "^3.2.25"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.0.0",
"throttle-debounce": "^3.0.1",
"vite": "^2.7.2"
},
"homepage": "https://github.com/tuqulore/vue-3-practices#readme",
"keywords": [
"vue3"
],
"license": "MIT",
"main": "",
"repository": {
"type": "git",
"url": "git+https://github.com/tuqulore/vue-3-practices.git"
},
"scripts": {
"build": "vite build",
"dev": "vite",
"dev:codesandbox": "CODESANDBOX=true vite",
"preview": "vite preview"
}
}
Binary file added practice-debounce-answer/public/favicon.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions practice-debounce-answer/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"infiniteLoopProtection": true,
"hardReloadOnChange": false,
"template": "nuxt",
"container": {
"port": 3000,
"startScript": "dev:codesandbox",
"node": "16"
}
}
38 changes: 38 additions & 0 deletions practice-debounce-answer/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script>
import {ref} from "vue"
/**
* throttle-debounceパッケージの使い方はドキュメントを参照しましょう
* 参考: https://www.npmjs.com/package/throttle-debounce
*/
import {debounce} from "throttle-debounce"
export default {
setup() {
const input = ref("")
const logs = ref([])
// debounceを使用することによって値を更新する処理の実行頻度を抑制することができます
const handleInput = debounce(1000, (event) => {
input.value = event.target.value
logs.value.push(event.target.value)
})
const handleClick = () => {
logs.value = []
}
return {input, logs, handleInput, handleClick}
}
}
</script>

<template>
<p>入力履歴の1番目に「test」という文字が表示されるようにしてください</p>
<input :value="input" @input="handleInput" />
<p>入力内容: {{input}}</p>
<h4>入力履歴</h4>
<button @click="handleClick">リセット</button>
<ol>
<li value="0">ここに入力履歴が追加されます</li>
<li v-for="(log, index) in logs" :key="index">{{log}}</li>
</ol>
</template>

<style>
</style>
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions practice-debounce-answer/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
14 changes: 14 additions & 0 deletions practice-debounce-answer/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
...(process.env.CODESANDBOX === "true" && {
server: {
hmr: {
port: 443
}
}
})
})
5 changes: 5 additions & 0 deletions practice-debounce/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
7 changes: 7 additions & 0 deletions practice-debounce/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Vue 3 + Vite

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)
13 changes: 13 additions & 0 deletions practice-debounce/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions practice-debounce/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "vue-3-practices-debounce",
"description": "演習 debounce",
"version": "1.0.0",
"author": "tuqulore Inc.",
"bugs": {
"url": "https://github.com/tuqulore/vue-3-practices/issues"
},
"dependencies": {
"vue": "^3.2.25"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.0.0",
"throttle-debounce": "^3.0.1",
"vite": "^2.7.2"
},
"homepage": "https://github.com/tuqulore/vue-3-practices#readme",
"keywords": [
"vue3"
],
"license": "MIT",
"main": "",
"repository": {
"type": "git",
"url": "git+https://github.com/tuqulore/vue-3-practices.git"
},
"scripts": {
"build": "vite build",
"dev": "vite",
"dev:codesandbox": "CODESANDBOX=true vite",
"preview": "vite preview"
}
}
Binary file added practice-debounce/public/favicon.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions practice-debounce/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"infiniteLoopProtection": true,
"hardReloadOnChange": false,
"template": "nuxt",
"container": {
"port": 3000,
"startScript": "dev:codesandbox",
"node": "16"
}
}
37 changes: 37 additions & 0 deletions practice-debounce/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script>
import {ref} from "vue"
/**
* throttle-debounceパッケージの使い方はドキュメントを参照しましょう
* 参考: https://www.npmjs.com/package/throttle-debounce
*/
import {debounce} from "throttle-debounce"
export default {
setup() {
const input = ref("")
const logs = ref([])
const handleInput = (event) => {
input.value = event.target.value
logs.value.push(event.target.value)
}
const handleClick = () => {
logs.value = []
}
return {input, logs, handleInput, handleClick}
}
}
</script>

<template>
<p>入力履歴の1番目に「test」という文字が表示されるようにしてください</p>
<input :value="input" @input="handleInput" />
<p>入力内容: {{input}}</p>
<h4>入力履歴</h4>
<button @click="handleClick">リセット</button>
<ol>
<li value="0">ここに入力履歴が追加されます</li>
<li v-for="(log, index) in logs" :key="index">{{log}}</li>
</ol>
</template>

<style>
</style>
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions practice-debounce/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
14 changes: 14 additions & 0 deletions practice-debounce/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
...(process.env.CODESANDBOX === "true" && {
server: {
hmr: {
port: 443
}
}
})
})

0 comments on commit 1dd9fbb

Please sign in to comment.