mixin.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* 目前nuxt 版本如果不高于 1.0.0 并不支持vuex的方法,因此获取相对于的东西只能通过this.$store.state来获取
  2. 如果nuxt框架为 1.0.0以上,vuex属性状态这里可以优化
  3. */
  4. import BScroll from 'better-scroll'
  5. import Vue from 'vue'
  6. // import { mapState } from 'vuex'
  7. Vue.mixin({
  8. computed: {
  9. user() {
  10. return this.$store.state.option.user
  11. },
  12. sortEnterprises () {
  13. if (this.user.data.enterprises) {
  14. let ens = this.user.data.enterprises.slice()
  15. if (ens && ens.length) {
  16. ens.sort(function (a, b) {
  17. return b.lastLoginTime - a.lastLoginTime
  18. })
  19. }
  20. return ens
  21. } else {
  22. return ''
  23. }
  24. }
  25. },
  26. methods: {
  27. goLastPage: function () {
  28. window.history.back(-1)
  29. },
  30. preventTouchMove (e) {
  31. e.preventDefault()
  32. },
  33. stopPropagation: function (e) {
  34. if (e) {
  35. e.stopPropagation()
  36. }
  37. },
  38. _initscroll() {
  39. if (!this.initSctoll) {
  40. this.initSctoll = new BScroll(this.$refs.mobileModalBox, {
  41. click: true
  42. })
  43. } else {
  44. this.initSctoll.refresh()
  45. }
  46. }
  47. }
  48. })