the language switching function is needed in the development of the project, and the style is implemented by vue-element "s select selector. The
code is as follows:
< div class= "language" >
<el-select v-model="value" @change="currentSel">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
< / div >
data () {
return {
options: [{
value: "",
label: ""
},
{
value: "",
label: ""
}, {
value: "English",
label: "English"
}],
value: ""
}
},
methods: {
currentSel(selVal){
if(selVal === ""){
// this.value = selVal
this.$i18n.locale="zhCHS"
console.log("");
}else if(selVal === ""){
this.$i18n.locale="zhCHT";
console.log("");
}else if(selVal === "English"){
this.$i18n.locale="en";
console.log("English");
}
}
}
Note: the default language of $i18n set in main.js is simplified Chinese
the above code works normally. When you click to switch languages, the page can switch between different languages normally. For example, when you switch to English mode (English can be displayed normally at this time), then refresh the interface and return to the default simplified Chinese mode
.how can I save the status of the user switching languages so that it will not be reset as the interface is refreshed
may ask more rookie, but can not figure out how to operate, hope that the boss will not hesitate to give advice, thank you!
or provide other ways to solve