MIxins不在VueJS

时间:2018-05-19 21:20:54

标签: javascript vue.js

我有代码:

main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import VueSession from 'vue-session'
import BootstrapVue from 'bootstrap-vue'
import App from './App'
import router from './router'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

import AuthHelper from './utils/AuthHelper'

Vue.config.productionTip = false
Vue.use(BootstrapVue)
Vue.use(VueSession)

Vue.mixin(AuthHelper)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

AuthHelper.js

export default {
  methods: {
    isLogged () {
      if (!this.$session.exists()) {
        this.$router.push({
          name: 'Login'
        })
      }
    },
    logout: () => {
      this.$session.destroy()
      this.$router.push({
        name: 'Login'
      })
    }
  }
}

我的问题是我不能在组件中使用方法isLogged()。每次我有错误,this.isLogged()不是一个函数。

我很困惑,因为我和文档一样。

@edit 在组件I中使用:

export default {
  name: 'Profil',
  data () {
    return {
      user: this.$session.get('user'),
      oldpass: '',
      newpass: '',
      newpassrepeat: '',
      error: [],
      error2: []
    }
  },
  created () {
    this.isLogged()
  }
}

0 个答案:

没有答案