undefinedfix
Sign in

Using the vux framework, it is found that this. $vux cannot be obtained, which leads to an error in the loading component. How to solve this problem?

Secil edited in Sun, 25 Apr 2021
      <div style="padding: 15px;">
            <x-button @click.native="showLoading" type="primary">显示loading(2s后关闭)</x-button>
        </div>

showLoading () {
            this.$vux.loading.show({
                text: 'Loading'
            })
            setTimeout(() => {
                this.$vux.loading.hide()
            }, 2000)
        },

Uncaught type error: cannot read property 'loading' of undefined

Old fellow iron, help to look at >

5 Replies
AverageGod
commented on Sun, 25 Apr 2021
import  { LoadingPlugin } from 'vux'
Vue.use(LoadingPlugin)
Ventuneac
commented on Mon, 26 Apr 2021

The direction of this

setTimeout(() => {
    this.$vux.loading.hide()//this指向
}, 2000)
link1xbetonline6
commented on Mon, 26 Apr 2021

Is vuex too late to initialize

Amer
commented on Mon, 26 Apr 2021

First of all main.js Import {loadingplugin} from 'vux' Vue.use (LoadingPlugin)

Then, when using it, pay attention to the use of this. In ES6's arrow syntax () = > {} such a function uses this asynchronously, and there is no problem in pointing. However, if you use the JS function: function () {}, if you use this in asynchrony, the direction of this will change, and this error will be reported!

user618856
commented on Mon, 26 Apr 2021

Landlord, has the problem been solved? I made the same mistake

lock This question has been locked and the reply function has been disabled.