Skip to content
This repository has been archived by the owner on Dec 25, 2017. It is now read-only.

bug: vm.$options, can not find asserts #188

Closed
sandwich99 opened this issue Apr 13, 2016 · 12 comments
Closed

bug: vm.$options, can not find asserts #188

sandwich99 opened this issue Apr 13, 2016 · 12 comments

Comments

@sandwich99
Copy link

请修复BUG, 或者在 readme 中注明

谢谢

@kazupon
Copy link
Owner

kazupon commented Apr 13, 2016

Sorry, I cannot understand chinese...
Can you use the english please?

@sandwich99
Copy link
Author

When use vue-validator work with vue-router, vue-router has to been loaded after vue-validator, otherwise will report error.

I am not sure if there is the bug of vue or vue-validator, if not, please note in readme, vue-validator and vue-router have loading order dependency

@sandwich99 sandwich99 changed the title BUG: 配合 vue-router 使用, 需要在加载 Router 之前加载 Validator, 否则vm.$options, 找不到asserts bug: vm.$options, can not find asserts Apr 15, 2016
@kazupon
Copy link
Owner

kazupon commented Apr 17, 2016

Thank you for your feedback 😺

When use vue-validator work with vue-router, vue-router has to been loaded after vue-validator, otherwise will report error.

Can you provide the reproduction codes with jsfiddle (or other) please?

@sandwich99
Copy link
Author

sandwich99 commented Apr 20, 2016

It's hard to reproduction in jsbin

cause in browser env, router and validator will be auto installed.

Vue.use(VueValidator)
Vue.use(CustomValidatorsPlugin)
Vue.use(Router)

//初始化router
const router = new Router({history: false })
setupRoute(router) //success
Vue.use(Router)
Vue.use(VueValidator)
Vue.use(CustomValidatorsPlugin)

//初始化router
const router = new Router({history: false })
setupRoute(router) //success
Vue.use(Router)
//初始化router
const router = new Router({history: false })
setupRoute(router)

Vue.use(VueValidator) //error

image

@kazupon
Copy link
Owner

kazupon commented Apr 21, 2016

Thank you for your great reporting!!

Hmm, In my environment (commonjs), I could not confirm this issue...

@kazupon
Copy link
Owner

kazupon commented Apr 27, 2016

Related kazupon/vue-i18n#28

@sqal
Copy link

sqal commented Apr 27, 2016

When use vue-validator work with vue-router, vue-router has to been loaded after vue-validator, otherwise will report error.

Actually i found that importing router instance from one file and installing vue-validator in another is causing error for me: Here's my setup:

index.js - entry point

import Vue from 'vue';
import VueValidator from 'vue-validator';
Vue.use(VueValidator);

Vue.config.debug = true

import router from './router';
...

router.js

import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';

Vue.use(VueRouter);

const router = new VueRouter({
  hashbang: false,
  history: true,
});

router.map(routes);

export default router;

And with this setup i am getting error - Uncaught TypeError: Cannot read property 'minlength' of undefined

(whole console log http://prntscr.com/axiijm)

even if try to use vue-validator after router import (in any place inside index.js really). But when i move vue-validator to router.js, everything works as expected

import Vue from 'vue';
import VueValidator from 'vue-validator';
import VueRouter from 'vue-router';
import routes from './routes';

Vue.use(VueValidator);
Vue.use(VueRouter);

const router = new VueRouter({
  hashbang: false,
  history: true,
});

router.map(routes);

export default router;

Any idea why is this happening?

@kazupon
Copy link
Owner

kazupon commented Apr 29, 2016

In my enviroment, I reproduced this issue.

This issue occured when execute router#start method in advance of installation with Vue.use when we use vue-router plugin.
We must install with Vue.use in advance of router#start.

@sqal
Copy link

sqal commented May 2, 2016

Hi @kazupon I updated vue-validator to 2.1.0 and.. previous minlength bug is gone but unfortunately, I am still having some issues with vue-validator & vue-router working together, check this example: http://www.webpackbin.com/E1sjGml-W

Console throws error when you try to open foo route:

Uncaught TypeError: Cannot read property 'required' of undefined

But when you install vue-validator inside router.js then error is gone. What is going on here?

The docs says now:

if you are using vue-router, you must install with Vue.use() in advance of router#start.

but i start my app router.start() after vue-validator installation, or perhaps I don't understand it properly?

@kazupon
Copy link
Owner

kazupon commented May 2, 2016

I checked your reproduction codes.

import router from './router'

router#map had been run inside router.js in advance of vue-validator installing.
I have found that the component is evaluated with vue-router when I confirmed it.

We must install it with Vue.use in advance of initializing vue-router.

@sqal
Copy link

sqal commented May 2, 2016

All right. Understood. Thank you.

@kazupon
Copy link
Owner

kazupon commented May 2, 2016

@sqal If you could resolve this issue, please tell me.
I'll try to update the documentation. 😺

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants