title.js 681 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;
        }
    }
};

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