0👍
✅
The reason is because window.vm
is only set to vm
after the App is mounted.
Whereas, the declare of data() in HeaderSearch/Index.vue is done before the App is mounted.
So in order to do this, the most elegant solution is the one you has found in your comment and I really support doing so: https://github.com/kazupon/vue-i18n/issues/149#issuecomment-357455921
However, if you wanna make sure and play around with vue lifecycle, You can try still keep your old code and instead doing this in HeaderSearch/index.vue
<script>
import * as myValidator from '@/myValidator' <-- this line
export default {
name: 'Index',
data() {
return {
rules: {
search: null <-- assign to nothing first
},
mounted() {
// update it after mounted:
this.rules.search = myValidator.accountValidatorRule <--- the window.vm should be ready now
}
...
}
Source:stackexchange.com