title.js 801 Bytes
import {
  SET_TITLE
} from 'store/yoho/types';

const getTitle = vue => {
  const {title} = vue.$options;

  if (title) {
    return typeof title === 'function' ? title.call(vue) : title;
  }
};
const serverTitleMixin = {
  created() {
    const title = getTitle(this);

    if (title) {
      this.$ssrContext.title = title;
      this.$store.commit(SET_TITLE, {title});
    }
  }
};

const clientTitleMixin = {
  mounted() {
    const title = getTitle(this);

    if (title) {
      document.title = title;
    }
  },
  methods: {
    auth() {
      if (!this.$store.state.yoho.context.isLogin) {
        this.$yoho.goLogin();
        return false;
      } else {
        return true;
      }
    }
  }
};

export default process.env.VUE_ENV === 'server' ?
  serverTitleMixin :
  clientTitleMixin;