I use the following markup (vuetify checkbox) to make my checkboxes required.
If mycomputed would be part of data everything would work, but since I use vuex
mycomputed is part of computed.
The bug only happens when using webpack vue-cli 2.
Bug 1: check Yes, uncheck Yes -> validation errors occur, check No - validation errors don't go away.
Bug 2: Reload page, nothing is checked, call validateAll -> validation succeeds (this happens because the Value="Y/N" is validated instead of the v-model)
HotFix
The following function is used inside vee-validate to check if the supplied v-model path is valid,
var hasPath = function (path, target) {
var obj = target;
return path.split('.').every(function (prop) {
if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
return false;
}
obj = obj[prop];
return true;
});
};
but .hasOwnProperty returns false for all computed properties.
main.js
import Vue from 'vue'
import App from './App'
import Vuetify from 'vuetify'
import 'vuetify/dist/vuetify.min.css'
import VeeValidate from 'vee-validate';
Vue.use(VeeValidate)
Vue.use(Vuetify)
new Vue({
el: '#app',
components: { App },
template: '<App/>'
})
Expected behavior
using computed properties in v-model should behave the same way as using data
Demo Link
This demo shows, that the bug does not apear outside webpack
https://codepen.io/lindwurm/pen/qYYMpa?editors=1010Reasoning
(as far as I understand ):in the codepen scenario template compilition will occur in the browser, while in the webpack scenario template compilation happens inside webpack. But data() is a function and will always be called in the browser, while computed: is an object (containing functions) and will be prepared by webpack and inherited down to the component in the browser.
Versions
Describe the bug
I use the following markup (vuetify checkbox) to make my checkboxes required. If
mycomputed
would be part ofdata
everything would work, but since I use vuexmycomputed
is part ofcomputed
. The bug only happens when using webpack vue-cli 2.Bug 1: check Yes, uncheck Yes -> validation errors occur, check No - validation errors don't go away.
Bug 2: Reload page, nothing is checked, call validateAll -> validation succeeds (this happens because the Value="Y/N" is validated instead of the v-model)
HotFix
The following function is used inside vee-validate to check if the supplied v-model path is valid,
but
.hasOwnProperty
returns false for all computed properties.when replacing the questionable line of code with
everything works fine. Also this codereplacement worked:
if (!(prop in obj)) {
I don't know if this has any sideeffects?
To Reproduce (edited) Setting up an minimal project and replace two files
App.vue
Expected behavior using computed properties in v-model should behave the same way as using data
Demo Link This demo shows, that the bug does not apear outside webpack https://codepen.io/lindwurm/pen/qYYMpa?editors=1010 Reasoning (as far as I understand ):in the codepen scenario template compilition will occur in the browser, while in the webpack scenario template compilation happens inside webpack. But data() is a function and will always be called in the browser, while computed: is an object (containing functions) and will be prepared by webpack and inherited down to the component in the browser.