Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save connecteev/87c152716ffda6d8ada757713ec30d9d to your computer and use it in GitHub Desktop.
Save connecteev/87c152716ffda6d8ada757713ec30d9d to your computer and use it in GitHub Desktop.
Diff to remove all instances of Axios
diff --git a/components/InfiniteLoader.vue b/components/InfiniteLoader.vue
index 47f9892..4895bb4 100644
--- a/components/InfiniteLoader.vue
+++ b/components/InfiniteLoader.vue
@@ -107,11 +107,12 @@ export default {
this.io = null;
return;
}
- const result = await this.$axios.$get(this.url || this.controls.next_page_url, {
+ const result = await $fetch(this.url || this.controls.next_page_url, {
params: {
page: ++this.controls.current_page,
},
- });
+ }).catch((error) => error.data);
+
this.controls = {
...result,
data: [...this.controls.data, ...result.data],
diff --git a/components/NewsFeed/NewsFeedContentCard.vue b/components/NewsFeed/NewsFeedContentCard.vue
index 4209f7d..8b4c48b 100644
--- a/components/NewsFeed/NewsFeedContentCard.vue
+++ b/components/NewsFeed/NewsFeedContentCard.vue
@@ -155,8 +155,11 @@ export default {
},
toggleBookmark() {
- this.$axios.post('/me/bookmarkUnbookmark', {
+ $fetch('/me/bookmarkUnbookmark', {
+ method: 'POST',
+ body: {
parent_id: this.postObjData.id,
+ }
})
.then(response => {
// console.log('response', response);
diff --git a/components/Post/PostCommentBox.vue b/components/Post/PostCommentBox.vue
index 5070ceb..c13d09c 100644
--- a/components/Post/PostCommentBox.vue
+++ b/components/Post/PostCommentBox.vue
@@ -98,8 +98,8 @@ export default {
},
submitComment() {
- // Note: alternatively, we can use async-await with axios
- // await this.$axios.post('/me/comments/create', {
+ // Note: alternatively, we can use async-await with $fetch
+ // await $fetch('/me/comments/create', { method: 'POST', data: { ...this.form.data() });
this.form.post('/me/comments/create', {
...this.form.data(),
})
@@ -132,7 +132,7 @@ export default {
duration : 3000,
"theme": "outline", // 'toasted-primary', 'outline', 'bubble'
});
- console.log('axios FAIL', response.errors);
+ console.log('form post FAIL', response.errors);
// this.form.onFail(response.data.errors);
});
},
diff --git a/components/partials/FollowUserButton.vue b/components/partials/FollowUserButton.vue
index 54545f1..baa4f76 100644
--- a/components/partials/FollowUserButton.vue
+++ b/components/partials/FollowUserButton.vue
@@ -38,8 +38,11 @@ export default {
methods: {
toggleFollowThisUser() {
- this.$axios.post('/me/followUnfollow', {
+ $fetch('/me/followUnfollow', {
+ method: 'POST',
+ body: {
username: this.usernameToFollow,
+ }
})
.then(response => {
if (!response.data || !response.data.data) {
diff --git a/middleware/premium.js b/middleware/premium.js
index c91fd94..a3b01ba 100755
--- a/middleware/premium.js
+++ b/middleware/premium.js
@@ -4,19 +4,17 @@
// Note: middleware kicks in only if specified globally in nuxt.config.js, or in a .vue component file or page (example: middleware: "hideTestRoutes",)
// See https://nuxtjs.org/guide/routing#middleware
-import axios from 'axios'
-
export default function (context) {
let loggedinUserId = parseInt(context.app.$cookies.get('loggedinUserId')); // makes use of cookie-universal-nuxt
if (!loggedinUserId) {
return context.redirect('/upgrade');
}
- axios.get(`https://my-json-server.typicode.com/connecteev/typicode_demo/users`)
+ $fetch(`https://my-json-server.typicode.com/connecteev/typicode_demo/users`)
.then(response => {
if (!response || !response.data) {
return context.redirect('/upgrade');
}
- console.log('axios response: users', response);
+ console.log('fetch response: users', response);
// Example from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
const usersJson = response.data;
@@ -35,19 +33,19 @@ export default function (context) {
}
// store.commit('setSession', response)
- // axios.get(`https://my-json-server.typicode.com/connecteev/typicode_demo/plans`)
+ // $fetch(`https://my-json-server.typicode.com/connecteev/typicode_demo/plans`)
// .then(response => {
- // console.log('axios response: plans', response);
+ // console.log('fetch response: plans', response);
// // store.commit('setSession', response)
// })
// .catch(() => {
- // console.log('axios exception');
+ // console.log('fetch exception');
// // store.commit('clearSession')
// });
})
.catch(() => {
- console.log('axios exception');
+ console.log('fetch exception');
// store.commit('clearSession')
});
}
diff --git a/nuxt.config.js b/nuxt.config.js
index 4fe42ef..c6bb93f 100644
--- a/nuxt.config.js
+++ b/nuxt.config.js
@@ -23,15 +23,6 @@ export default {
// See https://nuxtjs.org/api/configuration-dev
//dev: (process.env.NODE_ENV !== 'production'),
- /*
- ** Axios module configuration
- ** See https://axios.nuxtjs.org/options
- */
- // For Daniel Roe's code: https://gist.github.com/danielroe/3bdcb8640ae18631f686b4b07df887d2
- axios: {
- baseURL: `${backendApiUrl}/api/v1/` // set to `${backendApiUrl}` in https://github.com/connecteev/nuxt-laravel-passport-example
- },
-
/*
** Customize the progress-bar color
* For implementing a custom loader see https://nuxtjs.org/examples/custom-loading
@@ -57,7 +48,6 @@ export default {
** Plugins to load before mounting the App
*/
plugins: [
- "@/plugins/axios",
"@/plugins/myGlobalConstants",
"@/plugins/myGlobalComponents",
"@/plugins/mixins/myGlobalMixins",
@@ -71,8 +61,6 @@ export default {
** Nuxt.js modules
*/
modules: [
- // Doc: https://axios.nuxtjs.org/usage
- "@nuxtjs/axios",
"@nuxtjs/pwa",
"@nuxtjs/dotenv",
"@nuxtjs/toast",
diff --git a/package.json b/package.json
index 2af2bb6..d7878ad 100644
--- a/package.json
+++ b/package.json
@@ -11,38 +11,35 @@
"generate": "nuxt generate"
},
"dependencies": {
- "@fortawesome/fontawesome-svg-core": "^1.2.28",
- "@fortawesome/free-brands-svg-icons": "^5.13.0",
- "@fortawesome/free-regular-svg-icons": "^5.13.0",
- "@fortawesome/free-solid-svg-icons": "^5.13.0",
- "@fortawesome/vue-fontawesome": "^0.1.9",
- "@nuxtjs/axios": "^5.10.3",
- "@nuxtjs/dotenv": "^1.4.1",
- "@nuxtjs/pwa": "^3.0.0-beta.20",
+ "@fortawesome/fontawesome-svg-core": "^6.4.0",
+ "@fortawesome/free-brands-svg-icons": "^6.4.0",
+ "@fortawesome/free-regular-svg-icons": "^6.4.0",
+ "@fortawesome/free-solid-svg-icons": "^6.4.0",
+ "@fortawesome/vue-fontawesome": "^3.0.3",
+ "@nuxtjs/axios": "^5.13.6",
+ "@nuxtjs/dotenv": "^1.4.0",
+ "@nuxtjs/pwa": "^3.3.5",
"@nuxtjs/toast": "^3.3.0",
- "@tailwindcss/ui": "^0.1.4",
- "cookie-universal-nuxt": "^2.1.4",
- "dayjs": "^1.8.26",
- "js-cookie": "^2.2.0",
+ "@tiptap/core": "^2.0.4",
+ "cookie-universal-nuxt": "^2.2.2",
+ "dayjs": "^1.11.9",
+ "js-cookie": "^3.0.5",
"localStorage": "^1.0.4",
- "nuxt": "^2.12.2",
+ "nuxt": "^3.6.5",
"nuxt-fontawesome": "^0.4.0",
- "tiptap": "^1.27.1",
- "tiptap-extensions": "^1.29.1",
- "vform": "^1.0.1",
- "vue-clickaway": "^2.2.2",
- "vue-plyr": "^5.1.3",
- "vue-stripe-elements-plus": "^0.3.2"
+ "vform": "^2.1.2",
+ "vue-plyr": "^7.0.0",
+ "vue-stripe-elements-plus": "^1.0.3"
},
"devDependencies": {
"@fortawesome/fontawesome-free": "^5.13.0",
"eslint-plugin-nuxt": "^0.4.3",
"eslint-plugin-prettier": "^3.1.3",
- "node-sass": "^4.14.1",
- "nodemon": "^1.19.4",
- "postcss-import": "^12.0.1",
- "postcss-nested": "^4.2.1",
- "sass-loader": "^7.3.1",
- "tailwindcss": "^1.4.6"
+ "node-sass": "^9.0.0",
+ "nodemon": "^3.0.1",
+ "postcss-import": "^14.0.0",
+ "postcss-nested": "^6.0.1",
+ "sass-loader": "^13.3.2",
+ "tailwindcss": "^3.3.3"
}
}
diff --git a/pages/_user/_post/comments.vue b/pages/_user/_post/comments.vue
index 5ba2934..b8b7786 100644
--- a/pages/_user/_post/comments.vue
+++ b/pages/_user/_post/comments.vue
@@ -228,7 +228,7 @@ export default {
}
// get data about the user
- let userApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/users/' + authorSlug);
+ let userApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/users/' + authorSlug);
if (!userApiResponse || !userApiResponse.data || !userApiResponse.data.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -236,7 +236,7 @@ export default {
userObj = myGlobalConstants.globalUtilityFunctions.sanitizeUserAndProfile(userObj);
// Get data for the post
- let postsApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/posts/' + authorSlug + "/" + postSlug + "?comments=all");
+ let postsApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/posts/' + authorSlug + "/" + postSlug + "?comments=all");
if (!postsApiResponse || !postsApiResponse.data || !postsApiResponse.data.data) {
// post was not found
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist..' });
diff --git a/pages/_user/_post/delete_confirm.vue b/pages/_user/_post/delete_confirm.vue
index 569fe37..17cc6ca 100644
--- a/pages/_user/_post/delete_confirm.vue
+++ b/pages/_user/_post/delete_confirm.vue
@@ -174,7 +174,7 @@ export default {
}
// get data about the user
- let userApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/users/' + authorSlug);
+ let userApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/users/' + authorSlug);
if (!userApiResponse || !userApiResponse.data || !userApiResponse.data.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -182,7 +182,7 @@ export default {
userObj = myGlobalConstants.globalUtilityFunctions.sanitizeUserAndProfile(userObj);
// Get data for the post
- let postsApiResponse = await context.$axios.get('/me/posts/show/' + authorSlug + "/" + postSlug + "?comments");
+ let postsApiResponse = await $fetch('/me/posts/show/' + authorSlug + "/" + postSlug + "?comments");
if (!postsApiResponse || !postsApiResponse.data || !postsApiResponse.data.data) {
// post was not found
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist..' });
diff --git a/pages/_user/_post/index.vue b/pages/_user/_post/index.vue
index 13078c4..72874e0 100644
--- a/pages/_user/_post/index.vue
+++ b/pages/_user/_post/index.vue
@@ -352,9 +352,12 @@ export default {
},
toggleLikeThisPost() {
- this.$axios.post('/me/likeUnlike', {
+ $fetch('/me/likeUnlike', {
+ method: 'POST',
+ body: {
parent_id: this.postData.id,
parent_type: 'post'
+ }
})
.then(response => {
// console.log('response', response);
@@ -375,9 +378,12 @@ export default {
},
toggleBookmarkThisPost() {
- this.$axios.post('/me/bookmarkUnbookmark', {
+ $fetch('/me/bookmarkUnbookmark', {
+ method: 'POST',
+ body: {
parent_id: this.postData.id,
// parent_type: 'post'
+ }
})
.then(response => {
// console.log('response', response);
@@ -436,7 +442,7 @@ export default {
if (this.postData && this.postData.id) {
// Get all my reactions (likes, bookmarks) to an existing post
- let myPostReactionsApiResponse = await this.$axios.get('/me/getMyPostReactions/' + this.postData.id);
+ let myPostReactionsApiResponse = await $fetch('/me/getMyPostReactions/' + this.postData.id);
if (!myPostReactionsApiResponse || !myPostReactionsApiResponse.data || !myPostReactionsApiResponse.data.data) {
throw({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -448,7 +454,7 @@ export default {
let usernameToCheck = this.postAuthorData.userName;
if (this.username != usernameToCheck) {
// Check if I am following the user
- let amIFollowingUserApiResponse = await this.$axios.get('/me/amIFollowingUser?username=' + usernameToCheck);
+ let amIFollowingUserApiResponse = await $fetch('/me/amIFollowingUser?username=' + usernameToCheck);
if (!amIFollowingUserApiResponse || !amIFollowingUserApiResponse.data || !amIFollowingUserApiResponse.data.data) {
throw({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -479,7 +485,7 @@ export default {
}
// Get data about the user. This API call is needed to get the detailed user profile data that is not available in the Post API response
- let userApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/users/' + authorSlug);
+ let userApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/users/' + authorSlug);
if (!userApiResponse || !userApiResponse.data || !userApiResponse.data.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -487,7 +493,7 @@ export default {
userObj = myGlobalConstants.globalUtilityFunctions.sanitizeUserAndProfile(userObj);
// Get data for the post
- let postsApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/posts/' + authorSlug + "/" + postSlug + "?comments");
+ let postsApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/posts/' + authorSlug + "/" + postSlug + "?comments");
if (!postsApiResponse || !postsApiResponse.data || !postsApiResponse.data.data) {
// post was not found
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist..' });
@@ -499,7 +505,7 @@ export default {
let sanitizedPost = myGlobalConstants.globalUtilityFunctions.sanitizePost(returnedPost);
// get data for user's other posts (for this API call, we dont need the current logged-in user's bookmarks)
- let userPostsApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/posts?username=' + authorSlug + '&viewBy=latest');
+ let userPostsApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/posts?username=' + authorSlug + '&viewBy=latest');
if (!userPostsApiResponse || !userPostsApiResponse.data || !userPostsApiResponse.data.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
diff --git a/pages/_user/comment/_comment/delete_confirm.vue b/pages/_user/comment/_comment/delete_confirm.vue
index 61596e2..215b9f3 100755
--- a/pages/_user/comment/_comment/delete_confirm.vue
+++ b/pages/_user/comment/_comment/delete_confirm.vue
@@ -114,7 +114,7 @@ export default {
methods: {
async deleteComment() {
- await this.$axios.delete('/me/comments/' + this.commentHash + '/delete')
+ await $fetch('/me/comments/' + this.commentHash + '/delete', { method: 'DELETE' })
.then((response) => {
if ((response.status == 200) || (response.status == 201)) {
if (response.data && response.data.success) {
@@ -134,7 +134,7 @@ export default {
"theme": "outline", // 'toasted-primary', 'outline', 'bubble'
});
- console.log('axios FAIL', response.errors);
+ console.log('fetch FAIL', response.errors);
// this.form.onFail(response.data.errors);
});
},
@@ -226,7 +226,7 @@ export default {
}
// Get data for the comment
- let commentApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/comments/' + commentAuthorHandle + "/" + commentHash + "?nested");
+ let commentApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/comments/' + commentAuthorHandle + "/" + commentHash + "?nested");
if (!commentApiResponse || !commentApiResponse.data || !commentApiResponse.data.data) {
// comment was not found
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist..' });
diff --git a/pages/_user/comment/_comment/edit.vue b/pages/_user/comment/_comment/edit.vue
index cad9b9b..0c24f9b 100755
--- a/pages/_user/comment/_comment/edit.vue
+++ b/pages/_user/comment/_comment/edit.vue
@@ -141,8 +141,11 @@ export default {
methods: {
async editComment() {
- await this.$axios.patch('/me/comments/' + this.commentHash + '/update', {
+ await $fetch('/me/comments/' + this.commentHash + '/update', {
+ method: 'PATCH',
+ body: {
'body' : this.form.body,
+ }
})
.then((response) => {
if (response.status == 200) {
@@ -163,7 +166,7 @@ export default {
"theme": "outline", // 'toasted-primary', 'outline', 'bubble'
});
- console.log('axios FAIL', response.errors);
+ console.log('fetch FAIL', response.errors);
// this.form.onFail(response.data.errors);
});
},
@@ -205,7 +208,7 @@ export default {
}
// Get data for the comment
- let commentApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/comments/' + commentAuthorHandle + "/" + commentHash + "?nested");
+ let commentApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/comments/' + commentAuthorHandle + "/" + commentHash + "?nested");
if (!commentApiResponse || !commentApiResponse.data || !commentApiResponse.data.data) {
// comment was not found
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist..' });
diff --git a/pages/_user/comment/_comment/index.vue b/pages/_user/comment/_comment/index.vue
index 59d098d..bafb2ce 100644
--- a/pages/_user/comment/_comment/index.vue
+++ b/pages/_user/comment/_comment/index.vue
@@ -123,7 +123,7 @@ export default {
}
// Get data for the comment
- let commentApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/comments/' + commentAuthorHandle + "/" + commentHash + "?nested");
+ let commentApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/comments/' + commentAuthorHandle + "/" + commentHash + "?nested");
if (!commentApiResponse || !commentApiResponse.data || !commentApiResponse.data.data) {
// comment was not found
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist..' });
diff --git a/pages/_user/comments.vue b/pages/_user/comments.vue
index dc4501f..0812763 100644
--- a/pages/_user/comments.vue
+++ b/pages/_user/comments.vue
@@ -51,7 +51,7 @@ export default {
}
// Get data for the comments
- let commentApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/comments/' + commentAuthorHandle);
+ let commentApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/comments/' + commentAuthorHandle);
if (!commentApiResponse || !commentApiResponse.data || !commentApiResponse.data.data) {
// comments not found
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist..' });
diff --git a/pages/_user/index.vue b/pages/_user/index.vue
index b16ee9a..84e3c6d 100644
--- a/pages/_user/index.vue
+++ b/pages/_user/index.vue
@@ -146,7 +146,7 @@ export default {
let usernameToCheck = this.$route.params.user;
if (this.username != usernameToCheck) {
// Check if I am following the user
- let amIFollowingUserApiResponse = await this.$axios.get('/me/amIFollowingUser?username=' + usernameToCheck);
+ let amIFollowingUserApiResponse = await $fetch('/me/amIFollowingUser?username=' + usernameToCheck);
if (!amIFollowingUserApiResponse || !amIFollowingUserApiResponse.data || !amIFollowingUserApiResponse.data.data) {
throw({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -174,7 +174,7 @@ export default {
}
// Get data about the user. This API call is needed to get the detailed user profile data that is not available in the Post API response
- let userApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/users/' + userHandle);
+ let userApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/users/' + userHandle);
if (!userApiResponse || !userApiResponse.data || !userApiResponse.data.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -183,7 +183,7 @@ export default {
// Get data for user comments
let totalUserCommentsCount = 0;
- let commentApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/comments/' + userHandle + "?maxComments=5");
+ let commentApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/comments/' + userHandle + "?maxComments=5");
if (!commentApiResponse || !commentApiResponse.data || !commentApiResponse.data.data) {
// comments not found
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist..' });
@@ -204,7 +204,7 @@ export default {
// get data for author posts (feed), and append the currently logged-in user's bookmarked posts
postsByUserApiUrl = '/me/getPostsWithMyReactions?username=' + userHandle;
}
- let postsApiResponse = await context.$axios.get(postsByUserApiUrl);
+ let postsApiResponse = await $fetch(postsByUserApiUrl);
if (!postsApiResponse || !postsApiResponse.data || !postsApiResponse.data.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -218,9 +218,8 @@ export default {
// Note: We start with page=2 because content for page=1 needs to be manually loaded at the top (so we can show posts interspersed with comments)
// BASED ON @MrToxy on Discord: https://codesandbox.io/s/codesandbox-nuxt-706hx
// Works now...but no better than my solution - only the first set of posts show up in view-source.
- const userPosts = await context.$axios
// get data for author posts (feed) with bookmarks (empty if user is not logged in, or for currently logged-in user)
- .get(postsByUserApiUrl + '&page=2')
+ const userPosts = await $fetch(postsByUserApiUrl + '&page=2')
.then((response) => {
let postsData = response.data;
return postsData;
diff --git a/pages/auth/register.vue b/pages/auth/register.vue
index d7edb17..a3ab129 100755
--- a/pages/auth/register.vue
+++ b/pages/auth/register.vue
@@ -66,7 +66,10 @@ export default {
methods: {
async register() {
try {
- await this.$axios.post('/auth/register', this.form);
+ await $fetch('/auth/register', {
+ method: 'POST',
+ body: this.form
+ });
} catch(e) {
return;
}
diff --git a/pages/auth/socialCallback.vue b/pages/auth/socialCallback.vue
index 399a697..657f51c 100755
--- a/pages/auth/socialCallback.vue
+++ b/pages/auth/socialCallback.vue
@@ -74,7 +74,7 @@ export default {
});
})
.catch((response) => {
- // console.log('axios FAIL', response);
+ // console.log('fetch FAIL', response);
this.$toast.error("Sorry, we could not log you in. Please try again.", {
icon: "error",
duration : 5000,
diff --git a/pages/contact.vue b/pages/contact.vue
index 958bbd4..1f82be0 100644
--- a/pages/contact.vue
+++ b/pages/contact.vue
@@ -74,19 +74,25 @@ export default {
this.loaded = false;
this.success = false;
this.errors = {};
- this.$axios.post(this.action, this.fields).then(response => {
+
+ $fetch(this.action, {
+ method: 'POST',
+ body: this.fields
+ })
+ .then(response => {
this.fields = {}; //Clear input fields.
this.loaded = true;
this.success = true;
- }).catch(error => {
+ })
+ .catch(error => {
this.loaded = true;
if (error.response.status === 422) {
this.errors = error.response.data.errors || {};
}
});
+
}
},
-
},
}
diff --git a/pages/dashboard/followers.vue b/pages/dashboard/followers.vue
index ef81489..1f232ce 100644
--- a/pages/dashboard/followers.vue
+++ b/pages/dashboard/followers.vue
@@ -45,8 +45,7 @@ export default {
// Works now...but no better than my solution - only the first set of posts show up in view-source.
async asyncData({ app, req, params, error }) {
let myFollowerCount = 0;
- const usersFollowingMe = await app.$axios
- .get('/me/usersFollowingMe')
+ const usersFollowingMe = await $fetch('/me/usersFollowingMe')
.then((response) => {
if (response.data && response.data.total) {
myFollowerCount = response.data.total;
diff --git a/pages/dashboard/following.vue b/pages/dashboard/following.vue
index e9921e3..4a9da55 100644
--- a/pages/dashboard/following.vue
+++ b/pages/dashboard/following.vue
@@ -45,8 +45,7 @@ export default {
// Works now...but no better than my solution - only the first set of posts show up in view-source.
async asyncData(context) {
let myFollowerCount = 0;
- const usersIAmFollowing = await context.app.$axios
- .get('/me/usersIAmFollowing')
+ const usersIAmFollowing = await $fetch('/me/usersIAmFollowing')
.then((response) => {
if (response.data && response.data.total) {
myFollowerCount = response.data.total;
diff --git a/pages/dashboard/index.vue b/pages/dashboard/index.vue
index 4233b89..c6774a7 100644
--- a/pages/dashboard/index.vue
+++ b/pages/dashboard/index.vue
@@ -59,8 +59,7 @@ export default {
// Works now...but no better than my solution - only the first set of posts show up in view-source.
async asyncData({ app, req, params, error }) {
const data = {};
- const myPosts = await app.$axios
- .get('/me/posts/list')
+ const myPosts = await $fetch('/me/posts/list')
.then((response) => {
return response.data;
})
diff --git a/pages/index.vue b/pages/index.vue
index 7b9add4..ba7f0e2 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -92,7 +92,7 @@ export default {
methods: {
retrieveMyTotalBookmarksCount() {
- this.$axios.get('/me/getMyTotalReactionCounts?reactionTypes=bookmark')
+ $fetch('/me/getMyTotalReactionCounts?reactionTypes=bookmark')
.then(response => {
if (!response.data || !response.data.data || !response.data.data.myReactionCounts || !response.data.data.myReactionCounts.bookmark) {
throw({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
@@ -130,7 +130,7 @@ export default {
if (context.store.getters.isAuthenticated && context.store.getters.username) {
// Get data about the user
let userHandle = context.store.getters.username;
- let userApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/users/' + userHandle);
+ let userApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/users/' + userHandle);
if (!userApiResponse || !userApiResponse.data || !userApiResponse.data.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -141,7 +141,7 @@ export default {
// Get data for user's followed tags
let userFollowedTags = [];
if (!context.store.getters.getUserTags || (context.store.getters.getUserTags.length == 0) ) {
- let myTagsResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/userTags');
+ let myTagsResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/userTags');
if (!myTagsResponse || !myTagsResponse.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -154,7 +154,7 @@ export default {
let tagStreams = [];
let popularTags = [];
- let tagStreamsApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/tagStreams');
+ let tagStreamsApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/tagStreams');
if (tagStreamsApiResponse && tagStreamsApiResponse.data && tagStreamsApiResponse.data.data) {
tagStreams = tagStreamsApiResponse.data.data.featured_tags ? tagStreamsApiResponse.data.data.featured_tags : [];
popularTags = tagStreamsApiResponse.data.data.popular_tags ? tagStreamsApiResponse.data.data.popular_tags : [];
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 4f14fe9..9750a49 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -28,7 +28,7 @@ export default {
},
async asyncData (context) {
- // Important: if your Vuex action does an async / axios call, you need to use await when calling dispatch(), otherwise the Axios call may not execute!
+ // Important: if your Vuex action does an async / fetch call, you need to use await when calling dispatch(), otherwise the fetch call may not execute!
// See https://wildermuth.com/2019/04/22/Vuex-and-Asynchronicity
context.store.dispatch('resetPostFeed');
if (!context.store.getters.isAuthenticated) {
diff --git a/pages/index/latest.vue b/pages/index/latest.vue
index ea482ec..f18180e 100644
--- a/pages/index/latest.vue
+++ b/pages/index/latest.vue
@@ -31,7 +31,7 @@ export default {
// it potentially gets overridden by data() on the client-side, so be careful
// See https://nuxtjs.org/guide/async-data
async asyncData(context) {
- // Important: if your Vuex action does an async / axios call, you need to use await when calling dispatch(), otherwise the Axios call may not execute!
+ // Important: if your Vuex action does an async / fetch call, you need to use await when calling dispatch(), otherwise the fetch call may not execute!
// See https://wildermuth.com/2019/04/22/Vuex-and-Asynchronicity
context.store.dispatch('resetPostFeed');
if (!context.store.getters.isAuthenticated) {
diff --git a/pages/index/top/_slug.vue b/pages/index/top/_slug.vue
index a83a515..301c57a 100644
--- a/pages/index/top/_slug.vue
+++ b/pages/index/top/_slug.vue
@@ -67,7 +67,7 @@ export default {
return context.error({ statusCode: 404, message: "Sorry, the page you're trying to access was not found." });
}
- // Important: if your Vuex action does an async / axios call, you need to use await when calling dispatch(), otherwise the Axios call may not execute!
+ // Important: if your Vuex action does an async / fetch call, you need to use await when calling dispatch(), otherwise the fetch call may not execute!
// See https://wildermuth.com/2019/04/22/Vuex-and-Asynchronicity
context.store.dispatch('resetPostFeed');
if (!context.store.getters.isAuthenticated) {
diff --git a/pages/new/index.vue b/pages/new/index.vue
index 81527ad..42136e2 100644
--- a/pages/new/index.vue
+++ b/pages/new/index.vue
@@ -148,10 +148,13 @@ console.log('save draft', this.form);
// this.form.errors.clear();
// const { data } = await this.form.patch('/settings/update')
- // this.$axios.patch('/me/settings/account/update', {
+ // await $fetch('/me/settings/account/update', {
+ // method: 'PATCH',
+ // body: {
// 'userId': this.user.id,
// ...this.form.data(),
- // })
+ // }
+ // });
let postData = this.form.data();
console.log('this.form.data()', postData);
@@ -184,7 +187,7 @@ console.log('this.form.data()', postData);
"theme": "outline", // 'toasted-primary', 'outline', 'bubble'
});
- console.log('axios FAIL', response.errors);
+ console.log('fetch FAIL', response.errors);
// this.isLoading = false;
// this.form.onFail(response.data.errors);
});
diff --git a/pages/podcast/_slug.vue b/pages/podcast/_slug.vue
index e924dbb..98c9a14 100644
--- a/pages/podcast/_slug.vue
+++ b/pages/podcast/_slug.vue
@@ -391,7 +391,7 @@ export default {
//console.log('asyncData has executed!', 'server=', process.server, 'client=', process.client);
try {
let podcastSlug = context.params.slug;
- let podcastEpisodeDataResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/podcast-episodes/' + podcastSlug);
+ let podcastEpisodeDataResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/podcast-episodes/' + podcastSlug);
if (!podcastEpisodeDataResponse) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
diff --git a/pages/podcast/index.vue b/pages/podcast/index.vue
index 0cad733..9018762 100644
--- a/pages/podcast/index.vue
+++ b/pages/podcast/index.vue
@@ -77,7 +77,7 @@ export default {
async asyncData (context) {
//console.log('asyncData has executed!', 'server=', process.server, 'client=', process.client);
try {
- let allPodcastsDataResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/podcast-episodes/');
+ let allPodcastsDataResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/podcast-episodes/');
if (!allPodcastsDataResponse) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
diff --git a/pages/readingList/index.vue b/pages/readingList/index.vue
index 93e5e3f..0feb3b2 100644
--- a/pages/readingList/index.vue
+++ b/pages/readingList/index.vue
@@ -54,8 +54,7 @@ export default {
// BASED ON @MrToxy on Discord: https://codesandbox.io/s/codesandbox-nuxt-706hx
// Works now...but no better than my solution - only the first set of posts show up in view-source.
async asyncData(context) {
- const myBookmarks = await context.app.$axios
- .get("/me/getMyBookmarks")
+ const myBookmarks = await $fetch("/me/getMyBookmarks")
.then(response => {
if (response.data && response.data.total) {
context.store.dispatch('updateReadingListCount', response.data.total);
diff --git a/pages/search.vue b/pages/search.vue
index d28220e..b61be0c 100644
--- a/pages/search.vue
+++ b/pages/search.vue
@@ -92,7 +92,7 @@ export default {
// Get data for user's followed tags
let userFollowedTags = [];
if (!context.store.getters.getUserTags || (context.store.getters.getUserTags.length == 0) ) {
- let myTagsResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/userTags');
+ let myTagsResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/userTags');
if (!myTagsResponse || !myTagsResponse.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
@@ -105,7 +105,7 @@ export default {
let tagStreams = [];
let popularTags = [];
- let tagStreamsApiResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/tagStreams');
+ let tagStreamsApiResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/tagStreams');
if (tagStreamsApiResponse && tagStreamsApiResponse.data && tagStreamsApiResponse.data.data) {
tagStreams = tagStreamsApiResponse.data.data.featured_tags ? tagStreamsApiResponse.data.data.featured_tags : [];
popularTags = tagStreamsApiResponse.data.data.popular_tags ? tagStreamsApiResponse.data.data.popular_tags : [];
diff --git a/pages/search/index.vue b/pages/search/index.vue
index 9074869..d00b2eb 100644
--- a/pages/search/index.vue
+++ b/pages/search/index.vue
@@ -32,7 +32,7 @@ export default {
methods: {
retrieveMyTotalBookmarksCount() {
- this.$axios.get('/me/getMyTotalReactionCounts?reactionTypes=bookmark')
+ $fetch('/me/getMyTotalReactionCounts?reactionTypes=bookmark')
.then(response => {
if (!response.data || !response.data.data || !response.data.data.myReactionCounts || !response.data.data.myReactionCounts.bookmark) {
throw({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
@@ -64,7 +64,7 @@ export default {
// it potentially gets overridden by data() on the client-side, so be careful
// See https://nuxtjs.org/guide/async-data/#using-async-await
async asyncData (context) {
- // Important: if your Vuex action does an async / axios call, you need to use await when calling dispatch(), otherwise the Axios call may not execute!
+ // Important: if your Vuex action does an async / fetch call, you need to use await when calling dispatch(), otherwise the fetch call may not execute!
// See https://wildermuth.com/2019/04/22/Vuex-and-Asynchronicity
context.store.dispatch('resetPostFeed');
let searchQuery = (context.route.query && context.route.query.q) ? context.route.query.q : '';
diff --git a/pages/settings/account.vue b/pages/settings/account.vue
index 949a03e..7472de3 100644
--- a/pages/settings/account.vue
+++ b/pages/settings/account.vue
@@ -77,12 +77,16 @@ export default {
// this.form.errors.clear();
// const { data } = await this.form.patch('/settings/update')
- // this.$axios.patch('/me/settings/account/update', {
+ // await $fetch('/me/settings/account/update', {
+ // method: 'PATCH',
+ // body: {
// 'userId': this.user.id,
// 'userOriginalUsername': this.user.username,
// 'userOriginalEmail': this.user.email,
// ...this.form.data(),
- // })
+ // }
+ // });
+
this.form.patch('/me/settings/account/update', {
...this.form.data(),
})
@@ -115,7 +119,7 @@ export default {
"theme": "outline", // 'toasted-primary', 'outline', 'bubble'
});
- console.log('axios FAIL', response.errors);
+ console.log('fetch FAIL', response.errors);
// this.isLoading = false;
// this.form.onFail(response.data.errors);
});
diff --git a/pages/settings/notifications.vue b/pages/settings/notifications.vue
index fd43441..1d04e23 100644
--- a/pages/settings/notifications.vue
+++ b/pages/settings/notifications.vue
@@ -126,7 +126,7 @@ export default {
async asyncData (context) {
try {
// Get user notification settings
- let notificationSettingsApiResponse = await context.$axios.get('/me/settings/notifications');
+ let notificationSettingsApiResponse = await $fetch('/me/settings/notifications');
if (!notificationSettingsApiResponse || !notificationSettingsApiResponse.data) {
// notification settings not found
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist..' });
@@ -185,7 +185,7 @@ export default {
"theme": "outline", // 'toasted-primary', 'outline', 'bubble'
});
- console.log('axios FAIL', response.errors);
+ console.log('fetch FAIL', response.errors);
// this.isLoading = false;
// this.form.onFail(response.data.errors);
});
diff --git a/pages/tag/_id.vue b/pages/tag/_id.vue
index 7ff3a77..c649554 100644
--- a/pages/tag/_id.vue
+++ b/pages/tag/_id.vue
@@ -121,7 +121,7 @@ export default {
try {
// get data for current tag
let currentTagSlug = context.params.id;
- let currentTagResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/tags/' + currentTagSlug);
+ let currentTagResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/tags/' + currentTagSlug);
let currentTag = null;
if (currentTagResponse && currentTagResponse.data && currentTagResponse.data.data) {
currentTag = currentTagResponse.data.data;
diff --git a/pages/tag/_id/index.vue b/pages/tag/_id/index.vue
index 2a2d391..449e92f 100644
--- a/pages/tag/_id/index.vue
+++ b/pages/tag/_id/index.vue
@@ -34,7 +34,7 @@ export default {
async asyncData (context) {
let currentTagSlug = context.params.id;
- // Important: if your Vuex action does an async / axios call, you need to use await when calling dispatch(), otherwise the Axios call may not execute!
+ // Important: if your Vuex action does an async / fetch call, you need to use await when calling dispatch(), otherwise the fetch call may not execute!
// See https://wildermuth.com/2019/04/22/Vuex-and-Asynchronicity
context.store.dispatch('resetPostFeed');
diff --git a/pages/tag/_id/latest.vue b/pages/tag/_id/latest.vue
index 88c623f..9c2d4b4 100644
--- a/pages/tag/_id/latest.vue
+++ b/pages/tag/_id/latest.vue
@@ -39,7 +39,7 @@ export default {
async asyncData(context) {
let currentTagSlug = context.params.id;
- // Important: if your Vuex action does an async / axios call, you need to use await when calling dispatch(), otherwise the Axios call may not execute!
+ // Important: if your Vuex action does an async / fetch call, you need to use await when calling dispatch(), otherwise the fetch call may not execute!
// See https://wildermuth.com/2019/04/22/Vuex-and-Asynchronicity
context.store.dispatch('resetPostFeed');
if (!context.store.getters.isAuthenticated) {
diff --git a/pages/tag/_id/top/_slug.vue b/pages/tag/_id/top/_slug.vue
index 46202f4..f49f218 100644
--- a/pages/tag/_id/top/_slug.vue
+++ b/pages/tag/_id/top/_slug.vue
@@ -66,7 +66,7 @@ export default {
}
let currentTagSlug = context.params.id;
- // Important: if your Vuex action does an async / axios call, you need to use await when calling dispatch(), otherwise the Axios call may not execute!
+ // Important: if your Vuex action does an async / fetch call, you need to use await when calling dispatch(), otherwise the fetch call may not execute!
// See https://wildermuth.com/2019/04/22/Vuex-and-Asynchronicity
context.store.dispatch('resetPostFeed');
diff --git a/pages/test/index.vue b/pages/test/index.vue
index d1e0794..104eafd 100644
--- a/pages/test/index.vue
+++ b/pages/test/index.vue
@@ -78,7 +78,7 @@
<div><nuxt-link to="/test/testAsyncData">testAsyncData</nuxt-link></div>
<div><nuxt-link to="/test/testAjaxInAsyncData">testAjaxInAsyncData</nuxt-link></div>
<div><nuxt-link to="/test/testAsyncVanillaJavascript">test async js functions in vanilla Js (callbacks, promises, async/await)</nuxt-link></div>
- <div><nuxt-link to="/test/testAjaxAxios">test Ajax and Axios</nuxt-link></div>
+ <div><nuxt-link to="/test/testAjaxFetch">test Ajax and Fetch</nuxt-link></div>
<div><nuxt-link to="/test/payments">test Payments</nuxt-link></div>
</div>
</template>
diff --git a/pages/test/payments/testStripePaymentsAndre.vue b/pages/test/payments/testStripePaymentsAndre.vue
index 4c2556e..42eb03f 100644
--- a/pages/test/payments/testStripePaymentsAndre.vue
+++ b/pages/test/payments/testStripePaymentsAndre.vue
@@ -154,8 +154,11 @@ export default {
}
try {
const body = this.paymentForm;
- const data = (await this.$axios.post('/me/payments/checkout', body)).data;
- console.log('response from axios post. data:', data);
+ const data = (await $fetch('/me/payments/checkout', {
+ method: 'POST',
+ body: body
+ })).data;
+ console.log('response from fetch post. data:', data);
// this.$router.push(this.$route.query.redirect ? this.$route.query.redirect : '/');
this.$toast.success("You are now subscribed!", {
diff --git a/pages/test/payments/testViewPlans.vue b/pages/test/payments/testViewPlans.vue
index b18a1a4..63e10ee 100644
--- a/pages/test/payments/testViewPlans.vue
+++ b/pages/test/payments/testViewPlans.vue
@@ -378,7 +378,9 @@ export default {
// Loads the payment intent key for the user to pay.
createSetupIntent() {
- this.$axios.post('/me/payments/createSetupIntent', {
+ $fetch('/me/payments/createSetupIntent', {
+ method: 'POST',
+ body: {}
}).then (function(response) {
let responseData = response.data;
this.intentToken = responseData.data.intentToken;
@@ -452,8 +454,11 @@ export default {
// Saves the payment method for the user and re-loads the payment methods.
savePaymentMethod(method) {
- this.$axios.post('/me/payments/postPaymentMethods', {
+ $fetch('/me/payments/postPaymentMethods',{
+ method: 'POST',
+ body: {
payment_method: method
+ }
}).then(function() {
this.loadPaymentMethods();
this.addPaymentStatus = 'SUBMIT_PAYMENT_INIT';
@@ -463,7 +468,7 @@ export default {
// Loads all of the payment methods for the user
loadPaymentMethods() {
this.paymentMethodsLoadStatus = 'PAYMENT_METHODS_NOT_LOADED';
- this.$axios.get('/me/payments/getPaymentMethods')
+ $fetch('/me/payments/getPaymentMethods')
.then(function(response) {
let responseData = response.data;
this.paymentMethods = responseData.data.paymentMethods;
@@ -493,8 +498,11 @@ export default {
removePaymentMethod(paymentID) {
if (confirm("Do you want to permanently delete this card or payment method?")) {
let requestSuccessful = true;
- this.$axios.post('/me/payments/removePaymentMethod', {
+ $fetch('/me/payments/removePaymentMethod', {
+ method: 'POST',
+ body: {
id: paymentID
+ }
}).then(function(response) {
let responseData = response.data;
requestSuccessful = responseData.success;
@@ -532,8 +540,11 @@ export default {
/*
// Updates the user's default payment method (server-side)
- this.$axios.post('/me/payments/updateDefaultPaymentMethod', {
+ $fetch('/me/payments/updateDefaultPaymentMethod', {
+ method: 'POST',
+ body: {
paymentMethodId: methodId
+ }
}).then(function(response) {
// this.$router.push(this.$route.query.redirect ? this.$route.query.redirect : '/');
this.$toast.success("Your default payment method has been updated!", {
@@ -575,7 +586,7 @@ export default {
// Gets the current subscription plan for the user
getCurrentSubscription() {
- this.$axios.get('/me/payments/getCurrentSubscription')
+ $fetch('/me/payments/getCurrentSubscription')
.then(function(response) {
let responseData = response.data;
if (responseData.data.is_subscribed && !responseData.data.is_canceled) {
@@ -625,9 +636,12 @@ export default {
// Can't change to the same plan they currently are on
return;
}
- this.$axios.put('/me/payments/createOrUpdateSubscription', {
+ $fetch('/me/payments/createOrUpdateSubscription', {
+ method: 'PUT',
+ body: {
stripePlanId: this.selectedPlan.stripe_plan_id,
paymentMethodId: this.selectedPaymentMethod
+ }
}).then(function(response) {
// this.$router.push(this.$route.query.redirect ? this.$route.query.redirect : '/');
this.$toast.success("You are now Subscribed!", {
@@ -661,8 +675,12 @@ export default {
}
try {
const body = this.paymentForm;
- const data = (await this.$axios.post('/me/payments/checkout', body)).data;
- // console.log('response from axios post. data:', data);
+ const data = (await $fetch('/me/payments/checkout',{
+ method: 'POST',
+ body: body
+ })
+ ).data;
+ // console.log('response from fetch post. data:', data);
// this.$router.push(this.$route.query.redirect ? this.$route.query.redirect : '/');
this.$toast.success("You are now subscribed!", {
@@ -690,7 +708,7 @@ export default {
// Get data for all plans
let paymentPlans = [];
- let myPlansResponse = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/plans');
+ let myPlansResponse = await $fetch('/' + process.env.backendPublicApiPrefix + '/plans');
if (!myPlansResponse || !myPlansResponse.data) {
return context.error({ statusCode: 404, message: 'Something went wrong. The link you clicked on may be broken or no longer exist.' });
}
diff --git a/pages/test/signup_login_with_email/login.vue b/pages/test/signup_login_with_email/login.vue
index bbc8cd0..eafa877 100644
--- a/pages/test/signup_login_with_email/login.vue
+++ b/pages/test/signup_login_with_email/login.vue
@@ -117,7 +117,11 @@ export default {
scope: '*',
password: this.form.password
}
- const data = (await this.$axios.post('auth/login', body)).data;
+
+ const data = (await $fetch('auth/login', {
+ method: 'POST',
+ body: body
+ })).data;
await this.$store.commit('SET_TOKEN', data.access_token);
await this.$store.dispatch('getUser');
this.$router.push(this.$route.query.redirect ? this.$route.query.redirect : '/');
diff --git a/pages/test/testAjaxAxios.vue b/pages/test/testAjaxFetch.vue
similarity index 81%
rename from pages/test/testAjaxAxios.vue
rename to pages/test/testAjaxFetch.vue
index e79951f..8a8daf0 100644
--- a/pages/test/testAjaxAxios.vue
+++ b/pages/test/testAjaxFetch.vue
@@ -32,8 +32,6 @@
</template>
<script>
-import axios from 'axios'
-
export default {
layout: "default",
@@ -51,8 +49,8 @@ export default {
testGetDog () {
/*
try {
- let response = this.$axios.get('https://dog.ceo/api/breeds/image/random');
- //let response = this.$axios.get('/' + process.env.backendPublicApiPrefix + '/tags');
+ let response = $fetch('https://dog.ceo/api/breeds/image/random');
+ //let response = $fetch('/' + process.env.backendPublicApiPrefix + '/tags');
console.log(response);
} catch (error) {
//console.error(error);
@@ -60,9 +58,7 @@ export default {
}
*/
- // this can also work:
- //this.$axios.get('https://dog.ceo/api/breeds/image/random')
- axios.get('https://dog.ceo/api/breeds/image/random')
+ $fetch('https://dog.ceo/api/breeds/image/random')
.then(({ data }) => {
console.log(data);
this.testGetDogOutput = data;
@@ -75,7 +71,7 @@ export default {
async testGetTags () {
try {
- const { data } = await this.$axios.get('/' + process.env.backendPublicApiPrefix + '/tags');
+ const { data } = await $fetch('/' + process.env.backendPublicApiPrefix + '/tags');
console.log(data);
this.testGetTagsOutput = data;
} catch (e) {
@@ -87,7 +83,7 @@ export default {
async testGetMyPosts() {
console.log('get my posts');
try {
- const { data } = await this.$axios.get('/me/posts/list?page=1');
+ const { data } = await $fetch('/me/posts/list?page=1');
console.log(data);
this.testGetMyPostsOutput = data;
} catch (e) {
@@ -97,7 +93,7 @@ export default {
},
async testGetLocalNuxtPage () {
try {
- const { data } = await axios.get('/tags');
+ const { data } = await $fetch('/tags');
console.log(data);
this.testLocalNuxtPageOutput = data;
} catch (e) {
diff --git a/pages/test/testAjaxInAsyncData.vue b/pages/test/testAjaxInAsyncData.vue
index 11ed570..f81d5e4 100644
--- a/pages/test/testAjaxInAsyncData.vue
+++ b/pages/test/testAjaxInAsyncData.vue
@@ -13,8 +13,6 @@
</template>
<script>
-import axios from 'axios';
-
export default {
layout: "default",
data() {
@@ -29,8 +27,8 @@ export default {
// it potentially gets overridden by data() on the client-side, so be careful
// See https://nuxtjs.org/guide/async-data/#using-async-await
async asyncData(context) {
- let {data} = await context.$axios.get('https://api.myjson.com/bins/qxr3r')
- //let data = await context.$axios.get('/' + process.env.backendPublicApiPrefix + '/tags');
+ let {data} = await $fetch('https://api.myjson.com/bins/qxr3r')
+ //let data = await $fetch('/' + process.env.backendPublicApiPrefix + '/tags');
return {
info:data,
dude:'123',
@@ -91,7 +89,7 @@ export default {
// Note: Alternatively you could do:
// asyncData(){
-// return axios.get('https://api.myjson.com/bins/qxr3r')
+// return $fetch('https://api.myjson.com/bins/qxr3r')
// .then(res => {
// return {info:res.data};
// })
diff --git a/pages/test/testAsyncData.vue b/pages/test/testAsyncData.vue
index 9302856..f5ba21f 100644
--- a/pages/test/testAsyncData.vue
+++ b/pages/test/testAsyncData.vue
@@ -29,7 +29,7 @@ export default {
// it potentially gets overridden by data() on the client-side, so be careful
// See https://nuxtjs.org/guide/async-data/#using-async-await
async asyncData ({ params }) {
- //let { data } = await axios.get('https://dog.ceo/api/breeds/image/random')
+ //let { data } = await $fetch('https://dog.ceo/api/breeds/image/random')
//console.log('asyncdata is executed!', 'server=', process.server, 'client=', process.client);
await new Promise(resolve => setTimeout(resolve, 15)); // delay in milliseconds
return {
diff --git a/pages/test/testInfiniteLoad.vue b/pages/test/testInfiniteLoad.vue
index 020c145..e2d7fbd 100644
--- a/pages/test/testInfiniteLoad.vue
+++ b/pages/test/testInfiniteLoad.vue
@@ -58,8 +58,7 @@ export default {
}
const data = {};
- const myPosts = await context.app.$axios
- .get(postsApiUrl)
+ const myPosts = await $fetch(postsApiUrl)
.then((response) => {
return response.data;
})
diff --git a/plugins/axios.js b/plugins/axios.js
deleted file mode 100755
index 8fa1528..0000000
--- a/plugins/axios.js
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-export default function ({ $axios, store }) {
- $axios.onError(error => {
- if (error && error.response && error.response.status === 422) {
- store.dispatch('validation/setErrors', error.response.data.errors);
- }
- return Promise.reject(error);
- });
-
- $axios.onRequest(() => {
- store.dispatch('validation/clearErrors');
- });
-
- // from Daniel Roe's code: https://gist.github.com/danielroe/3bdcb8640ae18631f686b4b07df887d2
- $axios.onResponseError(error => {
- if (error.response && error.response.status === 400) {
- // log the user out
- }
- });
-}
-*/
-
-export default (ctx) => {
- ctx.$axios.onRequest((config) => {
- if (ctx.store.state.token) {
- config.headers.common.Authorization = `Bearer ${ctx.store.state.token}`
- }
- })
-}
diff --git a/plugins/vform.js b/plugins/vform.js
index b7195b5..97af299 100644
--- a/plugins/vform.js
+++ b/plugins/vform.js
@@ -21,16 +21,13 @@ export default ({ app }, inject) => {
})
.then(response => {
this.finishProcessing();
-
resolve(response);
})
.catch(error => {
this.busy = false;
-
if (error.response) {
this.errors.set(this.extractErrors(error.response));
}
-
reject(error);
});
});
diff --git a/store/index.js b/store/index.js
index 26c558b..c8992a0 100644
--- a/store/index.js
+++ b/store/index.js
@@ -224,7 +224,7 @@ export const actions = {
finalUrl += '&viewBy=' + 'feed';
}
- const { data, status } = await this.$axios.get(finalUrl);
+ const { data, status } = await $fetch(finalUrl);
if (!data) {
throw ({ statusCode: 404, message: 'Something went wrong while retrieving the post feed. The link you clicked on may be broken or no longer exist.' });
} else {
@@ -256,7 +256,7 @@ export const actions = {
// From Nemanja's code on Discord
async getUser({ commit }) {
try {
- const data = (await this.$axios.get('auth/loggedinUser')).data;
+ const data = (await $fetch('auth/loggedinUser')).data;
if (data) {
commit('SET_USER', data.user);
this.$cookies.set('login_type', 'regular');
@@ -274,7 +274,7 @@ export const actions = {
},
async getUserSocialLogin({ commit }) {
try {
- const data = (await this.$axios.get('auth/me')).data;
+ const data = (await $fetch('auth/me')).data;
if (data) {
commit('SET_USER', data.data);
this.$cookies.set('login_type', 'social');
@@ -285,7 +285,7 @@ export const actions = {
},
async logout({ commit }) {
try {
- const data = (await this.$axios.post('auth/logout')).data;
+ const data = (await $fetch('auth/logout', { method: 'POST', body: {} })).data;
if (data) {
commit('LOGOUT');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment