1
1
# Vue Rate
2
2
3
- [ ![ npm version] ( https://badge.fury.io/js/vue-rate.svg )] ( https://www.npmjs.com/package/vue-rate )
4
- [ ![ npm] ( https://img.shields.io/npm/dt/vue-rate.svg )] ( https://www.npmjs.com/package/vue-rate )
3
+ [ ![ npm version] ( https://badge.fury.io/js/vue-rate@next .svg )] ( https://www.npmjs.com/package/vue-rate@next )
4
+ [ ![ npm] ( https://img.shields.io/npm/dt/vue-rate@next .svg )] ( https://www.npmjs.com/package/vue-rate@next )
5
5
6
- > Rate component for Vue - [ Demo] ( https://sinanmtl.github.io/vue-rate/ )
6
+ > Rate component for Vue - [ Demo] ( https://sinanmtl.github.io/vue-rate/ ) .
7
+ > Note: This version for Vue 3. If you want to use for Vue 2.x, please [ see] ( https://github.com/SinanMtl/vue-rate/tree/master ) .
7
8
8
9
## Installation and usage
9
10
10
11
Once, install rate component for your project
11
12
12
13
``` bash
13
- npm install vue-rate --save
14
+ npm install vue-rate@next --save
15
+ // or yarn add vue-rate@next
14
16
```
15
17
16
18
Import Vue Rate into your app
17
19
18
20
``` javascript
21
+ import { createApp } from ' vue'
19
22
import rate from ' vue-rate'
20
23
import ' vue-rate/dist/vue-rate.css'
21
24
22
- Vue .use (rate)
25
+ createApp (App)
26
+ .use (rate)
27
+ .mount (' #app' )
23
28
```
24
29
25
30
Use HTML template
@@ -83,36 +88,51 @@ Then add Rate component. `iconref` must be symbol's id
83
88
- ` v-model `
84
89
85
90
``` javascript
86
- new Vue ({
87
- ...
91
+ export default {
88
92
data: {
89
- return () {
90
- myRate: 0
91
- }
93
+ return () { myRate: 0 }
92
94
}
93
- ...
94
- })
95
+ }
95
96
```
96
97
98
+ or ` setup() ` in Option API
99
+ ``` javascript
100
+ import { ref } from ' vue' ;
101
+
102
+ export default {
103
+ setup () {
104
+ const myRate = ref (0 );
105
+ return { myRate }
106
+ }
107
+ }
108
+ ```
109
+
110
+ or Composition API with ` <script setup> `
111
+ ``` javascript
112
+ < script setup>
113
+ import { ref } from ' vue' ;
114
+ const myRate = ref (0 );
115
+ }
116
+ < script>
117
+ ```
118
+
119
+ And bind to component
97
120
``` html
98
121
<rate :length =" 5" v-model =" myRate" />
99
122
```
100
123
101
124
## Events
102
125
103
126
``` javascript
104
- new Vue ({
105
- ...
106
- methods: {
107
- onBeforeRate (rate ) {
108
- alert (rate)
109
- },
110
- onAfterRate (rate ) {
111
- alert (rate)
112
- }
113
- }
114
- ...
115
- })
127
+ < script setup>
128
+ function onBeforeRate (rate ) {
129
+ alert (rate)
130
+ }
131
+
132
+ function onAfterRate (rate ) {
133
+ alert (rate)
134
+ }
135
+ < / script>
116
136
```
117
137
118
138
``` html
@@ -125,8 +145,8 @@ new Vue({
125
145
3 . Make your changes on ` src/Rate.vue `
126
146
4 . Build the package
127
147
``` bash
128
- yarn build
129
- # or npm run build
148
+ npm run build
149
+ # or yarn build
130
150
```
131
151
5 . Commit and create PR
132
152
0 commit comments