Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 578c67c

Browse files
authored
chore: update readme (#3)
1 parent 5035699 commit 578c67c

File tree

2 files changed

+154
-3
lines changed

2 files changed

+154
-3
lines changed

‎README.md‎

Lines changed: 153 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,153 @@
1-
# vue-inheritance
2-
vue-inheritance
1+
# Vue Inheritance
2+
3+
### Introduction
4+
5+
vue-inheritance is an npm package designed for Vue.js projects. It provides a convenient way to manage and reuse component properties and methods. Leveraging Vue's extension and mixin capabilities, this package simplifies the definition and application of component attributes, making it more modular.
6+
7+
**Installation**
8+
9+
In your Vue project, install vue-inheritance using the following command:
10+
11+
```bash
12+
npm install vue-inheritance
13+
```
14+
15+
**Usage**
16+
17+
In your Vue project, import VueInheritance:
18+
19+
```
20+
import { VueInheritance } from 'vue-inheritance'
21+
```
22+
23+
**Define Interface Modules**
24+
25+
Define one or more props, methods, computed modules.
26+
27+
```javascript
28+
// IControl
29+
export const IControl = {
30+
props: {
31+
disabled: {
32+
type: Boolean,
33+
default: false
34+
}
35+
}
36+
}
37+
38+
// ITheme
39+
export const ITheme = {
40+
props: {
41+
theme: {
42+
type: String,
43+
default: 'Standard'
44+
}
45+
}
46+
}
47+
48+
// ILoading
49+
export const ILoading = {
50+
props: {
51+
isLoading: {
52+
type: Boolean,
53+
default: false
54+
}
55+
}
56+
}
57+
58+
59+
//IButton
60+
export const ILoading = VueInheritance
61+
.extend(IControl)
62+
.extend(ITheme)
63+
.extend({
64+
methods: {
65+
onClick(e) {
66+
this.$emit('click', e)
67+
}
68+
}
69+
})
70+
```
71+
72+
**Implement**
73+
74+
In your specific component, use the VueInheritance implement method to apply Interface modules.
75+
76+
```javascript
77+
// Button.vue
78+
export default {
79+
extends: VueInheritance.implement(IControl).implement(ITheme),
80+
methods: {
81+
onClick(e) {
82+
this.$emit('click', e)
83+
}
84+
}
85+
}
86+
87+
// or
88+
89+
export default {
90+
extends: IButton
91+
}
92+
```
93+
94+
**Extend**
95+
96+
In another component, use the extend method to inherit an existing component and the implement method to apply additional attribute modules.
97+
98+
```javascript
99+
// LoadingButton.vue
100+
import Button from './Button.vue'
101+
102+
export default {
103+
extends: VueInheritance.extend(Button).implement(ILoading)
104+
}
105+
```
106+
107+
**Examples**
108+
Button with IControl and ITheme
109+
110+
```vue
111+
<template>
112+
<button :disabled="disabled" :class="theme" @click="onClick">Click me</button>
113+
</template>
114+
115+
<script>
116+
import { VueInheritance } from 'vue-inheritance'
117+
import { IControl } from '@/core/IControl.js'
118+
import { ITheme } from '@/core/ITheme.js'
119+
120+
export default {
121+
extends: VueInheritance.implement(IControl).implement(ITheme),
122+
methods: {
123+
onClick(e) {
124+
this.$emit('click', e)
125+
}
126+
}
127+
}
128+
</script>
129+
```
130+
131+
Loading Button with ILoading
132+
133+
```vue
134+
<template>
135+
<Button :disabled="disabled || isLoading" :class="theme" @click="onClick">
136+
<span v-if="isLoading">Loading...</span>
137+
<span v-else>Click me</span>
138+
</Button>
139+
</template>
140+
141+
<script>
142+
import { VueInheritance } from 'vue-inheritance'
143+
import Button from './Button.vue'
144+
import { ILoading } from '@/core/ILoading.js'
145+
146+
export default {
147+
extends: VueInheritance.extend(Button).implement(ILoading)
148+
}
149+
</script>
150+
```
151+
152+
This way, you can define interface modules based on project requirements and flexibly apply and reuse them in your components.
153+

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-inheritance",
3-
"version": "1.0.1-beta.2",
3+
"version": "1.0.1-beta.3",
44
"description": "vue inheritance",
55
"main": "src/index.js",
66
"types": "src/index.d.ts",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /