Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
832 views
in Technique[技术] by (71.8m points)

vue.js - TypeError: Cannot read property 'indexOf' of undefined in Nuxt.js

I got this error in nuxtjs after login but I don't use indexOf anything in my code. I'm not sure, what is this problem. I'm try run on localhost, it's not error but I build my project to server, I got this error when login and then refresh page. In mounted function is not working, the page is not render. How to resolve this problem. Please help me.

TypeError: Cannot read property 'indexOf' of undefined
    at setAttr (app.bfdc54a.js:22087)
    at Array.updateAttrs (app.bfdc54a.js:22066)
    at invokeCreateHooks (app.bfdc54a.js:21449)
    at hydrate (app.bfdc54a.js:21798)
    at hydrate (app.bfdc54a.js:21776)
    at VueComponent.patch [as __patch__] (app.bfdc54a.js:21852)
    at VueComponent.Vue._update (app.bfdc54a.js:19511)
    at VueComponent.updateComponent (app.bfdc54a.js:19599)
    at Watcher.get (app.bfdc54a.js:19985)
    at new Watcher (app.bfdc54a.js:19974)

In nuxt.config.js

auth: {
    strategies: {
        local: {
            endpoints: {
                login: { url: 'login', method: 'post', propertyName: 'data' },
                 user: { url: 'me', method: 'get', propertyName: 'data' },
                 logout: { url: 'logout', method: 'post' }
            }
         }
    }
},

In my component

<template>
    <div>
        <a-button v-if="!$auth.loggedIn" @click="loginGuest">{{
        $t('header.signIn')
      }}</a-button>
      <template v-else>
        <template v-if="$auth.user.username">
          <p @click="logOutAsGuest">{{ $t('header.guest') }}</p>
        </template>
        <a v-else @click="$router.push('/profile')">
          <a-avatar
            :src="$auth.user.avatar"
          />
        </a>
      </template>
    </div>
</template>
<script>
    async mounted {
        const shipping = await this.$axios.get(`/shipping`)
        this.shippingList = shipping.data
        if (this.$auth.loggedIn) {
             const customerInfomation = await this.$axios.get(`customer`, {
                     header: { Authorization: this.$auth.getToken('local') },
        })
    }
    methods: {
        async loginGuest() {
            const guestLogin = await this.$auth.loginWith('local', { data: 'guest' })  
        }
    }
</script>
question from:https://stackoverflow.com/questions/65841164/typeerror-cannot-read-property-indexof-of-undefined-in-nuxt-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...