I need to translate the label (and placeholder) of vuetify text-field (v-text-field
). The code looks like this
<template>(...)
<v-text-field
label="$t('common.nameLabel')"
v-model="registerName"
required
></v-text-field>
<vuetify-google-autocomplete
ref="registerAddress"
id="map"
dark
label="registerAddressLabel"
google-api-key="Xyz"
v-on:placechanged="getAddressData"
>
</vuetify-google-autocomplete>
(...)</template>
<script>
import VuetifyGoogleAutocomplete from 'vuetify-google-autocomplete'
export default {
data () {
return {
registerAddressLabel () {
return this.$t('common.addressLabel')
},
registerAddress: '',
registerEmail: '',
registerPassword: '',
registerName: ''
}
},
methods: {
getAddressData (addressData, placeholderResultData) {
}
},
components: {
VuetifyGoogleAutocomplete
}
}
</script>
in the first case (also tried with autocomplete) the label is exactly ($t('common.nameLabel')
as a string). so it seems it doesn't handle as a function.
Is it possible to translate all labels this way?
You need to use v-bind
(or the colon shorthand) to pass a JavaScript value, otherwise it will just pass the string literal:
<v-text-field
v-bind:label="$t('common.nameLabel')"
v-model="registerName"
required></v-text-field>
Here's a little JSFiddle: https://jsfiddle.net/9rjpaz4L/
You can also do it without the word v-bind, just with the colon:
<v-text-field
:label="$t('common.nameLabel')"
v-model="registerName"
required>
</v-text-field>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With