import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from './components/element-ui'

import './styles/index.scss'

Vue.config.productionTip = false

Vue.use(ElementUI)

const title = document.title
Vue.prototype.$setTitle = (t) => {
  if (!title) {
    document.title = title
  } else {
    document.title = `${t} - ${title}`
  }
}
router.afterEach((to) => {
  if (to.meta?.title) {
    Vue.prototype.$setTitle(to.meta.title)
  }
})

const isMobile = () => window.innerWidth <= 1000
Vue.util.defineReactive(Vue.prototype, '$isMobile', isMobile())
window.addEventListener('resize', () => {
  Vue.prototype.$isMobile = isMobile()
})

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount('#app')
