Examples of code I've written in PHP, Javascript, SCSS, etc.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

edit-cards.vue 2.0 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div v-if="cards && cards.length > 0">
  3. <div class="saved-cards-heading">
  4. <h5>Card</h5> <h5>Default</h5> <h5>Delete</h5>
  5. </div>
  6. <div v-for="card in cards" :key="card.id" class="saved-card">
  7. <span>{{card.card.brand[0].toUpperCase() + card.card.brand.substring(1)}}
  8. (••••{{card.card.last4}})</span>
  9. <span><input :checked="card.id == preferred" :value="card.id" name="selected-card" type="radio"
  10. @change="change(card.id)"></span>
  11. <span><img @click="remove(card.id)" src="../../images/close-icon-black.svg"/></span>
  12. </div>
  13. <p id="billing-error"></p>
  14. </div>
  15. </template>
  16. <script>
  17. function get() {
  18. fetch('/panel/cards', {
  19. method: 'GET',
  20. headers: {'Content-Type': 'application/json',
  21. 'Accept': 'application/json',
  22. 'X-XSRF-TOKEN': this.token}
  23. }).then((response) => {response.json().then(data => {
  24. this.cards = data.data
  25. })})
  26. }
  27. function change(card) {
  28. fetch('/panel/change-card', {
  29. method: 'POST',
  30. headers: {'Content-Type': 'application/json',
  31. 'Accept': 'application/json',
  32. 'X-XSRF-TOKEN': this.token},
  33. body: JSON.stringify({'card': card})
  34. }).then((response) => {
  35. if (response.ok) {
  36. response.json().then((data) => {
  37. this.cards = data.data
  38. })
  39. } else {
  40. console.log('bad')
  41. document.getElementById("billing-error").textContent =
  42. `${response.status}: ${response.statusText}`
  43. }
  44. })
  45. }
  46. function remove(card) {
  47. if (card.length == 1) {
  48. return
  49. }
  50. fetch('/panel/delete-card', {
  51. method: 'POST',
  52. headers: {'Content-Type': 'application/json',
  53. 'Accept': 'application/json',
  54. 'X-XSRF-TOKEN': this.token},
  55. body: JSON.stringify({'card': card})
  56. }).then((response) => {
  57. if (response.ok) {
  58. response.json().then((data) => {
  59. this.cards = data.data
  60. })
  61. } else {
  62. document.getElementById("billing-error").textContent =
  63. `${response.status}: ${response.statusText}`
  64. }
  65. })
  66. }
  67. export default {
  68. data() {
  69. return {cards: null}
  70. },
  71. methods: {get, change, remove},
  72. created() {
  73. this.get()
  74. },
  75. props: ['token', 'preferred'],
  76. }
  77. </script>