我有问题。我想访问vee-validate.js文件中的我的吸气剂之一。 我该怎么办?
在我的页面和组件中(在export default{...}
之外的<script>
let lang;
function getLang({store}) {
lang = store.state.lang
}
export default{
...
}
部分中),我使用了以下功能:
component.vue
lang
但是它不起作用!
我正在尝试访问我的vuex中以store
状态存储的自定义lang文件(出于翻译目的),并将其用于vee-validate.js文件中以获取自定义消息。
我尝试导入import Vue from 'vue'
import { required } from 'vee-validate/dist/rules'
import { extend, ValidationObserver, ValidationProvider, setInteractionMode } from 'vee-validate'
import {store} from '../store'
let langFile = store
setInteractionMode('eager')
extend('required', {
...required,
message: ''
})
Vue.component('ValidationProvider', ValidationProvider);
Vue.component("ValidationObserver", ValidationObserver);
,但不起作用。
veevalidate.js:
import langfile from '../static/lang'
export const state = () => ({
lang: null,
dir: null,
})
export const getters = {
//----------------- Language and Direction
lang(state){
return state.lang
},
dir(state){
return state.dir
},
}
export const mutations = {
SET_LANGUAGE(state, lang){
state.lang = lang
},
SET_DIRECTION(state, dir){
state.dir = dir
},
}
export const actions = {
async nuxtServerInit({dispatch, commit}) {
// ------------- Read Language File
let baseLang = process.env.SITE_LANGUAGE;
let siteLang = langfile[baseLang];
let siteDir = langfile[baseLang]['dir'];
commit('SET_LANGUAGE', siteLang);
commit('SET_DIRECTION', siteDir);
},
}
更新:我的商店index.js
MyLocalizations