|
1 | | -# vue3-number-counter |
| 1 | +# Vue 3 Number Counter |
2 | 2 |
|
3 | | -This template should help get you started developing with Vue 3 in Vite. |
| 3 | +**Vue 3 animated number counter directive** |
4 | 4 |
|
5 | | -## Recommended IDE Setup |
| 5 | +<p align="center"> |
6 | 6 |
|
7 | | -[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin). |
| 7 | +[](https://www.npmjs.com/package/vue3-number-counter) |
| 8 | +[](https://www.npmjs.com/package/vue3-number-counter) |
8 | 9 |
|
9 | | -## Type Support for `.vue` Imports in TS |
| 10 | +</p> |
10 | 11 |
|
11 | | -TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types. |
12 | 12 |
|
13 | | -If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps: |
| 13 | +## Installing |
14 | 14 |
|
15 | | -1. Disable the built-in TypeScript Extension |
16 | | - 1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette |
17 | | - 2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)` |
18 | | -2. Reload the VSCode window by running `Developer: Reload Window` from the command palette. |
| 15 | +### Package manager |
19 | 16 |
|
20 | | -## Customize configuration |
| 17 | +Using npm: |
21 | 18 |
|
22 | | -See [Vite Configuration Reference](https://vitejs.dev/config/). |
| 19 | +```bash |
| 20 | +npm i vue3-number-counter |
| 21 | +``` |
| 22 | + |
| 23 | +Then, import and register the component: |
| 24 | + |
| 25 | + |
| 26 | +## Global Registration |
| 27 | + |
| 28 | +main.js |
| 29 | +``` |
| 30 | +import numberCounter from "vue3-number-counter"; |
| 31 | +app.use(numberCounter); |
| 32 | +``` |
| 33 | + |
| 34 | +## Local Registration |
| 35 | + |
| 36 | +* Composition API |
23 | 37 |
|
24 | | -## Project Setup |
| 38 | +``` |
| 39 | +<script setup> |
| 40 | +import { numberCounter as vNumberCounter } from "vue3-number-counter"; |
| 41 | +</script> |
| 42 | +``` |
25 | 43 |
|
26 | | -```sh |
27 | | -npm install |
| 44 | +* Options API |
| 45 | +``` |
| 46 | +<script> |
| 47 | +import { numberCounter } from "vue3-number-counter"; |
| 48 | +
|
| 49 | +export default { |
| 50 | + directives: { |
| 51 | + "number-counter": numberCounter |
| 52 | + }, |
| 53 | +} |
| 54 | +</script> |
28 | 55 | ``` |
29 | 56 |
|
30 | | -### Compile and Hot-Reload for Development |
31 | 57 |
|
32 | | -```sh |
33 | | -npm run dev |
| 58 | +## Usage |
| 59 | +* Example 1 |
| 60 | +``` |
| 61 | +import { numberCounter } from "vue3-number-counter"; |
| 62 | +
|
| 63 | +export default { |
| 64 | + directives: { |
| 65 | + "number-counter": numberCounter |
| 66 | + }, |
| 67 | + data () { |
| 68 | + return { |
| 69 | + counter: { |
| 70 | + countFrom: 0, |
| 71 | + countTo: 100, |
| 72 | + duration: 1000, |
| 73 | + text: "% completed" |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | +} |
| 78 | +
|
| 79 | +
|
| 80 | +<template> |
| 81 | + <div v-number-counter="counter">0% completed</div> |
| 82 | +</template> |
34 | 83 | ``` |
35 | 84 |
|
36 | | -### Type-Check, Compile and Minify for Production |
| 85 | +* Example 2 |
37 | 86 |
|
38 | | -```sh |
39 | | -npm run build |
| 87 | +``` |
| 88 | +<script setup> |
| 89 | +import { numberCounter as vNumberCounter } from "vue3-number-counter"; |
| 90 | +
|
| 91 | +const counter = { |
| 92 | + countFrom: 0, |
| 93 | + countTo: 100, |
| 94 | + duration: 1000, |
| 95 | + text: "% completed", |
| 96 | +}; |
| 97 | +</script> |
| 98 | +
|
| 99 | +<template> |
| 100 | + <div v-number-counter="counter">0% completed</div> |
| 101 | +</template> |
40 | 102 | ``` |
41 | 103 |
|
42 | | -### Lint with [ESLint](https://eslint.org/) |
| 104 | +* Example 3 |
43 | 105 |
|
44 | | -```sh |
45 | | -npm run lint |
46 | 106 | ``` |
| 107 | +const counter = { |
| 108 | + countFrom: 0, |
| 109 | + countTo: 100, |
| 110 | + duration: 1000, |
| 111 | + text: "% completed", |
| 112 | +}; |
| 113 | +</script> |
| 114 | +
|
| 115 | +<template> |
| 116 | + <div v-number-counter="counter">0% completed</div> |
| 117 | +</template> |
| 118 | +``` |
| 119 | + |
| 120 | + |
| 121 | +# Demo |
| 122 | +* https://vue-number-counter.netlify.app/ |
| 123 | + |
| 124 | +## License |
| 125 | +[](https://github.com/mustafadalga/vue3-number-counter/blob/main/LICENSE) |
0 commit comments