<template>
  <div class="language-switch">
    <el-select size="medium" v-model="value" @change="handleChange">
      <el-option v-for="item in languages" :key="item.value" :label="item.name" :value="item.value"> </el-option>
    </el-select>
  </div>
</template>

<script>
import Cookies from 'js-cookie'

export default {
  name: 'LanguageSwitch',
  data() {
    return {
      value: this.$i18n.locale,
      languages: [
        { name: '中文', value: 'zh-CN' },
        { name: 'English', value: 'en' }
      ]
    }
  },
  methods: {
    handleChange(value) {
      Cookies.set('lang', value, { expires: 30, domain: '.ezijing.com' })
      this.$i18n.locale = value
      /* 刷新页面 */
      this.$router.go(0)
    }
  }
}
</script>

<style lang="scss" scoped>
.language-switch {
  width: 100px;
  ::v-deep .el-input__inner {
    background: transparent;
    border: 0;
  }
}
</style>
