B
B
BKaiyrbekov2020-01-15 09:50:56
Vue.js
BKaiyrbekov, 2020-01-15 09:50:56

Porting from Vue.js to Nuxt.js?

Good afternoon! I am migrating my project from Vue.js to Nuxt.js and ran into this problem. there is a page "Open Dialogs", and in this page, users can ask a question to the project administrators for a given time. so the problem is that on vue the same conditions and codes work well and limitation and nuxt does not handle the
#nuxt.config.js error

axios: {
    baseURL: process.env.VUE_APP_API_URL
  },

#utilities.js
import Cookies from 'js-cookie'

function setAuthorizationHeader(axios) {
  axios.setHeader('X-CSRFTOKEN', Cookies.get('csrftoken'));
  return
}

export { setAuthorizationHeader }

store
import {setAuthorizationHeader} from '@/middleware/utilities'
...
  async commentNew({commit}, data) {
    try {
      setAuthorizationHeader(this.$axios);
      const url = '/comments/create/'
      const response = await this.$axios.post(url, data)
      return response.data
    } catch (error) {
      throw error
    }
  },
......

#component
async saveMessage() {
                this.error = null;
                this.saving = true;
                this.myMessageSend = true;

                try {
                    const obj = {
                        body: this.body,
                        parentType: this.parentType,
                        parentID: Number(this.parentID)
                    };
                    this.body = '';
                    const response = await this.$store.dispatch("common/commentNew", obj);
                    console.log('saveMessage, успешно-----' , response);
                } catch (error) {
                    console.log('saveMessage, ошибка -------', error);
                    console.log('saveMessage, ошибка response------', error.response);
                } finally {
                    this.saving = false;
                }
            },

when an event that fires on a component should return a response to me like in vue, but nuxt gives undefined
, it gives an error on vue,
5e1eb44c34256301968681.jpeg
and this is on nuxt,
5e1eb482c88cf248584744.jpeg
why undefined?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BKaiyrbekov, 2020-01-17
@BKaiyrbekov

Solved a problem:

$axios.interceptors.response.use(undefined, async (error) => { 
      return Promise.reject(error) // возвращаю все ошибки
    });

S
SleepGame, 2020-01-15
@SleepGame

So you have different errors, in the first server response 403.
and in the second, the script cannot read the variable in which the response was embedded
Check what generally comes in error
async commentNew({commit}, data) {
try {
setAuthorizationHeader(this.$axios);
const url = '/comments/create/'
const response = await this.$axios.post(url, data)
return response.data // Check response here
} catch (error) {
throw error
}
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question