使用Vuei18n和Vuetify使我感到困惑
这是我的代码(我注意到内联很奇怪):
public function register(){
$this->form_validation->set_values('name', 'Name', 'required|trim');
$this->form_validation->set_values('e-mail', 'e-mail', 'required|trim|valid_e-mail|is_unique[users.e-mail]');
$this->form_validation->set_rules('password1', 'Password1', 'required|trim|min_length[3]|matches[password2]', [
'matches' => 'Password dont matches',
'min_length' => 'Password too short'
]);
$this->form_validation->set_rules('password2', 'Password2', 'required|trim|matches[password1]');
}
如何自动翻译输入表单下的消息?
答案 0 :(得分:2)
创建计算出的emailRules,
computed: {
emailRules() {
return [
v => !!v || $t('E-mail is required')
];
}
},
然后修改您的行:“ v-text-field”中的规则
:rules="emailRules"
答案 1 :(得分:2)
我认为当规则即将失败时,vuetify会接受消息。
更改语言环境后,我根据更新规则进行了混合,以刷新规则消息。
import Vue from 'vue'
export default Vue.extend({
data: () => ({
formActive: true,
}),
computed: {
requiredRules() {
return this.formActive
? [(val: string) => !!val || this.$t('errors.requiredField')]
: []
},
},
methods: {
updateLocale() {
this.formActive = false
this.$nextTick(() => {
this.formActive = true
})
},
},
})
答案 2 :(得分:0)
<v-select
:items="getAllPriceGrups"
item-text="name"
@input="getPrices"
v-model="priceG"
filled
:rules="rulesRequired($t('global.needToFillOut'))"
return-object
></v-select>
methods: {
rulesRequired(role) {
return [value => !!value || role];
},
}
这对我有用!