| | |
| | | <template> |
| | | <h2>Add Resource</h2> |
| | | <base-card> |
| | | <form> |
| | | <form @submit.prevent="submitData"> |
| | | <div class="form-control"> |
| | | <label for="title">Title</label> |
| | | <input id="title" name="title" type="text" /> |
| | | <input id="title" name="title" type="text" ref="titleInput" /> |
| | | </div> |
| | | <div class="form-control"> |
| | | <label for="description">Description</label> |
| | | <textarea id="description" name="description" type="text" rows="3"></textarea> |
| | | <textarea |
| | | id="description" |
| | | name="description" |
| | | type="text" |
| | | rows="3" |
| | | ref="descInput" |
| | | ></textarea> |
| | | </div> |
| | | <div class="form-control"> |
| | | <label for="link">Link</label> |
| | | <input id="link" name="link" type="url" /> |
| | | <input id="link" name="link" type="url" ref="linkInput" /> |
| | | </div> |
| | | <div> |
| | | <base-button type="submit">Add Resource</base-button> |
| | |
| | | </template> |
| | | |
| | | <script> |
| | | export default {}; |
| | | export default { |
| | | inject: ['addResource'], |
| | | methods: { |
| | | submitData() { |
| | | const enteredTitle = this.$refs.titleInput.value; |
| | | const enteredDescription = this.$refs.descInput.value; |
| | | const enteredUrl = this.$refs.linkInput.value; |
| | | |
| | | this.addResource(enteredTitle, enteredDescription, enteredUrl); |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | |
| | | >Add Resource</base-button |
| | | > |
| | | </base-card> |
| | | <component :is="selectedTab"></component> |
| | | <KeepAlive> |
| | | <component :is="selectedTab"></component> |
| | | </KeepAlive> |
| | | </template> |
| | | |
| | | <script> |
| | |
| | | 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> |