【发布时间】:2019-05-16 08:32:46
【问题描述】:
我正在使用 vue create CLI 构建自定义 Vue JS 插件。我已经导入了各种包,但是在尝试将自定义设置与 VeeValidate 一起使用时出现错误。
plugin.js
/*
* NOTE:
* This file is plugin stub for main.js
*/
// Import required packages
import Vue from 'vue'
import VeeValidate from 'vee-validate'
import VueResource from 'vue-resource'
import BootstrapVue from 'bootstrap-vue'
// Import custom LES form styling
import './assets/scss/les-application.scss'
// Import our plugin
import plugin from './index'
/* Vue Validation */
const config = {
fieldsBagName: 'fields',
errorBagName: 'errors',
classes: true,
strict: false,
classNames: {
valid: '',
invalid: 'is-invalid'
},
events: 'change|blur',
validity: false,
inject: false,
aria: true,
delay: 0
}
Vue.use(require('vue-moment'))
Vue.use(VueResource)
Vue.use(VeeValidate, config)
Vue.use(plugin)
// Custom validation rules
/*
* NOTE:
* If you want Vue instance of main.js to import something in your plugin as a Vue option,
* you need to export it here.
*/
// export default plugin
main.js
import Vue from 'vue'
import App from './App.vue'
import './plugin'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
错误:
Property or method "errors" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
和
Cannot read property 'has' of undefined
我正在尝试找出我的配置中缺少什么,如果我从 plugin.js 中删除 VeeValidate 配置,那么它会使用默认的 VeeValidate 选项并且可以正常工作。
【问题讨论】:
-
实际使用 VeeValidate 的组件的代码在哪里?
-
代码在
/src/components/MyComponent.vue内 -
对对对,那我们能从
MyComponent.vue看到相关代码吗? -
@RyanHolton 我认为这是因为您禁用了自动注入。您需要在需要验证的每个组件中 request a new validator scope
-
@Sovalina 我将如何设置这个,我已经阅读了文档,但是我很困惑我的代码 sn-ps 会放在哪里
标签: vue.js vuejs2 vee-validate