I am using vue-i18n in a vue project. And I found it really confusing when using some data in vue data
with i18n. Then if I change locale
, that data is not reactive. I tried to return that data
from another computed data
but anyways it is not reactive because i18n is written in data
. *My situation - * I want to show table with dropdown(list of columns with checkbox) above it. When user checks a column it will be showed in table if unchecks it won't. It is working fine until I change locale
. After changing locale
table columns
is not translated but dropdown items
is reactively translated and my code won't work anymore. Here is some code to explain better: In my myTable.vue
component I use bootstrap-vue table -
template
in myTable.vue
<vs-dropdown vs-custom-content vs-trigger-click>
<b-link href.prevent class="card-header-action btn-setting" style="font-size: 1.4em">
<i class="fa fa-th"></i>
</b-link>
<vs-dropdown-menu class="columns-dropdown">
<visible-columns :default-fields="columns" @result="columnListener"></visible-columns>
</vs-dropdown-menu>
</vs-dropdown>
<b-table class="generalTableClass table-responsive" :fields="computedFieldsForTable">custom content goes here</b-table>
script
in myTable.vue
data(){
return {
fieldsForTable: [];
}
},
computed: {
computedFieldsForTable () {
return this.fieldsForTable;
},
columns() {
return [
{
key: 'id',
label: this.$t('id'),,
visible: true,
changeable: true
},
{
key: 'fullName',
label: this.$t('full-name'),,
visible: true,
changeable: true
},
{
key: 'email',
label: this.$t('email'),,
visible: true,
changeable: true
}
]
}
},
mounted () {
this.fieldsForTable = this.filterColumns(this.columns);
},
methods: {
filterColumns(columns = []) {
return columns.filter(column => {
if (column.visible) {
return column
}
})
},
columnListener ($event) {
this.fieldsForTable = this.filterColumns($event)
}
}
Can someone give me some advice for this situation ?
*EDIT AFTER SOME DEBUGGING: I think when filtering columns
(in computed
) and returning it for fieldsForTable
inside filterColumns(columns)
method, it actually returning array(of objects) with label='Label Name'
not label=this.$t('labelName')
. So after filtering the new array has nothing to do with vue-i18n. My last chance is reloading the page when locale changes.