forked from jigneshbhimani/VueJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path27Mixins.txt
79 lines (66 loc) · 2.05 KB
/
27Mixins.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
1) Make 2 components
- src/components/MixinA:
<template>
<div>
<h3>MixinA</h3>
<button @click="incrementData"> click {{count}}</button>
</div>
</template>
<script>
import CountOne from "../../mixins/countOne";
export default {
name: 'MixinA',
mixins: [CountOne] // mixins/countOne file ka code ko fetch karega
}
</script>
- src/components/MixinB:
<template>
<div>
<h3>MixinB</h3>
<button @click="incrementData"> click {{count}}</button>
</div>
</template>
<script>
import CountOne from "../../mixins/countOne";
export default {
name: 'MixinB',
mixins: [CountOne] // mixins/countOne file ka code ko fetch karega
}
</script>
2) Import both components in App.vue file
- src/App.vue:
<template>
<div id="app">
<MixinA />
<h2>============</h2>
<MixinB />
</div>
</template>
<script>
import MixinA from "./components/MixinA.vue";
import MixinB from "./components/MixinB.vue";
export default {
name: "App",
components: {
MixinA,
MixinB
},
};
</script>
- Every time we make a new component and this mixins so this is too long
3) so we can make a folder
- src/mixins:
4) After the creating a folder we can make a file in this folder
- src/mixins/countOne.js:
export default{
data(){
return{
count:0
}
},
methods: {
incrementData(){
this.count += 1;
}
}
}