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
80
| <template>
| <base-card>
| <base-button
| @click="setSelectedTab('stored-resources')"
| :mode="storedResButtonMode"
| >Stored Resource</base-button
| >
| <base-button
| @click="setSelectedTab('add-resource')"
| :mode="addResButtonMode"
| >Add Resource</base-button
| >
| </base-card>
| <KeepAlive>
| <component :is="selectedTab"></component>
| </KeepAlive>
| </template>
|
| <script>
| import StoredResources from './StoredResource.vue';
| import AddResource from './AddResource.vue';
|
| export default {
| components: {
| StoredResources: StoredResources,
| AddResource: AddResource,
| },
| data() {
| return {
| selectedTab: 'stored-resources',
| storedResouces: [
| {
| id: 'official-guide',
| title: 'Official Guide',
| description: 'The official Vue.js documentation',
| link: 'https://vuejs.org',
| },
| {
| id: 'google',
| title: 'Google',
| description: 'Learn to google...',
| link: 'https://google.com',
| },
| ],
| };
| },
| computed: {
| storedResButtonMode() {
| return this.selectedTab === 'stored-resources' ? null : 'flat';
| },
| addResButtonMode() {
| return this.selectedTab === 'add-resource' ? null : 'flat';
| },
| },
| provide() {
| return {
| resources: this.storedResouces,
| addResource: this.addResource,
| };
| },
| methods: {
| setSelectedTab(tab) {
| this.selectedTab = tab;
| },
| addResource(title, description, url) {
| const newResource = {
| id: new Date().toISOString(),
| title: title,
| description: description,
| link: url,
| };
|
| this.storedResouces.unshift(newResource);
| this.selectedTab = 'stored-resources';
| },
| },
| };
| </script>
|
| <style scoped></style>
|
|