A small and easy-to-use component to switch between languages in a dropdown menu, created by Vue.js.
https://aliafsah1988.github.io/vue-switch-lang/
npm i vue-switch-lang
In your parent component:
<template>
<div class="home">
<SwitchLang @changed="onChange" :initLang="initLang" :options="options" />
</div>
</template>
<script>
import SwitchLang from "vue-switch-lang";
export default {
components: {
SwitchLang
},
methods: {
onChange(lang) {
// Do something
}
},
data() {
return {
initLang: {
title: "en",
flag: "gb"
},
options: [
{
title: "en",
flag: "gb"
},
{
title: "de",
flag: "de"
},
{
title: "fa",
flag: "ir"
}
]
};
}
};
</script>
<style>
.multiselect__option--selected {
background-color: red;
}
.multiselect__option--highlight {
background-color: green;
background: green;
}
</style>
In the file that you instantiate Vue (usually main.js):
import Vue from "vue";
import App from "./App.vue";
import SwitchLang from "vue-switch-lang";
Vue.component("SwitchLang");
new Vue({
render: h => h(App)
}).$mount("#app");
npm install
npm run serve
npm run build
If you need a sample to create a multi language SPA with Vue.js with ability to change between right-to-left and left-to-right, please visit:
https://github.com/aliafsah1988/vue-multilang-sample
Author: aliafsah1988
Demo: https://aliafsah1988.github.io/vue-switch-lang/
Source Code: https://github.com/aliafsah1988/vue-switch-lang
#vue #vuejs #javascript