Skip to content

Commit 698e933

Browse files
committed
feat: adds vue3 support
1 parent 1f15fa3 commit 698e933

18 files changed

+980
-1033
lines changed

README.md

+46-26
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
# Vue Rate
22

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)
55

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).
78
89
## Installation and usage
910

1011
Once, install rate component for your project
1112

1213
```bash
13-
npm install vue-rate --save
14+
npm install vue-rate@next --save
15+
// or yarn add vue-rate@next
1416
```
1517

1618
Import Vue Rate into your app
1719

1820
```javascript
21+
import { createApp } from 'vue'
1922
import rate from 'vue-rate'
2023
import 'vue-rate/dist/vue-rate.css'
2124

22-
Vue.use(rate)
25+
createApp(App)
26+
.use(rate)
27+
.mount('#app')
2328
```
2429

2530
Use HTML template
@@ -83,36 +88,51 @@ Then add Rate component. `iconref` must be symbol's id
8388
- `v-model`
8489

8590
```javascript
86-
new Vue({
87-
...
91+
export default {
8892
data: {
89-
return () {
90-
myRate: 0
91-
}
93+
return () { myRate: 0 }
9294
}
93-
...
94-
})
95+
}
9596
```
9697

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
97120
```html
98121
<rate :length="5" v-model="myRate" />
99122
```
100123

101124
## Events
102125

103126
```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>
116136
```
117137

118138
```html
@@ -125,8 +145,8 @@ new Vue({
125145
3. Make your changes on `src/Rate.vue`
126146
4. Build the package
127147
```bash
128-
yarn build
129-
# or npm run build
148+
npm run build
149+
# or yarn build
130150
```
131151
5. Commit and create PR
132152

build.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Rate from './src/Rate.vue'
22

3-
function install(Vue) {
4-
Vue.component(Rate.name, Rate)
3+
function install(Vue, options = {}) {
4+
Vue.component(options.name || Rate.name || "rate", Rate)
55
global.Rate = Rate
66
}
77

dist/vue-rate.common.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export namespace plugin {
22
function install(): void
33
}
4+
5+
declare module "vue-rate" {
6+
export function install(): void
7+
}

0 commit comments

Comments
 (0)