This time I will show you how vue and vue-i18n realize the multi-language switching of background data. How vue and vue-i18n realize the multi-language switching of background data.Notes What are they? Here are actual cases. Let’s take a look.
In the XXX.js fileDefine the function:
getUser(context,info){ context.$http.get(SERVER_URL+'/users',info).then(function(data){ let err =data.body.error; if(err===0){ let dataObj = data.body.userLists; //获取后台返回的数据 this.users = dataObj.items.map(function (e,i) { //遍历获取的数据,用this.$t()将每项数据与翻译资源对应 e.gender=context.$t(e.gender); //context 是this, gender 与 diabetes_type 为每个items里的key;gender里的value有三种:'GDRNF'、‘GDRF'、‘GDRM' e.diabetes_type = context.$t(e.diabetes_type); return e; }); this.listLoading = false; // console.log(dataObj); } }) },
array;
The above method is to traverse the data obtained through the map function, using this.$ t() corresponds the value of items to the value in the translation resource, thereby realizing multi-language switching of background data;Part of the data in the en.json translation resource:
{ "GDRNF":"Not Fill", "GDRF":"Female", "GDRM":"Male", }
How to update the array with $set in vue.js
How to move the array in vue.js Position and update the view
The above is the detailed content of How vue and vue-i18n implement multi-language switching of background data. For more information, please follow other related articles on the PHP Chinese website!