Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. <template>
  2. <div>
  3. <!-- <router-link to="/dash">Back</router-link>-->
  4. <form>
  5. <label for="todo">Todo:</label>
  6. <br>
  7. <input id="todo" type="text" v-model="form.text">
  8. <br>
  9. <button @click="onClick">Submit</button>
  10. </form>
  11. </div>
  12. </template>
  13.  
  14. <script lang="ts">
  15. import Vue from "vue";
  16. import axios from 'axios';
  17.  
  18. export default Vue.extend({
  19. name: "Add",
  20. data() {
  21. return {
  22. form: {
  23. text: '',
  24. }
  25. }
  26. },
  27. methods: {
  28. onClick: async function (event: Event) {
  29. event.preventDefault();
  30. const response = await axios.post('http://localhost:8000/api/v1/todos/', {
  31. text: this.form.text,
  32. done: false
  33. }, {
  34. headers: {
  35. "Authorization": "Bearer " + this.$store.state.token
  36. }
  37. });
  38. if (response.status !== 201) {
  39. console.log(response);
  40. } else {
  41. await this.$router.push("/dash");
  42. }
  43. }
  44. }
  45. })
  46. </script>
  47.  
  48. <style scoped>
  49.  
  50. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement