2017-05-24 42 views
0

我正在使用Vue.js 2.3.3,Vue资源1.3.3,Vue路由器2.5.3,并且我正在尝试设置Vue-Auth。我不断收到一个控制台错误,但是,这说,auth.js?b7de:487 Error (@websanova/vue-auth): vue-resource.1.x.js : Vue.http must be set.。我在main.js中设置Vue.http,但vue-resource由于某种原因没有选择它。为什么要忽略vue-resource的Vue.http?

main.js:

import Vue from 'vue' 
import Actions from 'actions' 
import App from './App' 

Vue.use(Actions, { 
    locales: ['en', 'zh', 'fr'] 
}) 

Vue.http.options.root = 'https://api.example.com' 

new Vue({ 
    render: h => h(App), 
    watch: { 
    lang: function (val) { 
     Vue.config.lang = val 
    } 
    } 
}).$mount('#app') 

动作/ index.js

import VueResource from 'vue-resource' 
import Router from 'actions/router' 
import I18n from 'actions/i18n' 

export default { 
    install (Vue, options) { 
    Vue.use(Router) 
    Vue.use(I18n, options.locales) 
    Vue.use(require('@websanova/vue-auth'), { 
     router: require('@websanova/vue-auth/drivers/router/vue-router.2.x'), 
     auth: require('@websanova/vue-auth/drivers/auth/bearer'), 
     http: require('@websanova/vue-auth/drivers/http/vue-resource.1.x') 
    }) 
    } 
} 

如果我正下方Vue.use(Router)添加Vue.use(VueResource)到行动/ index.js,我得到一个新的错误:Error (@websanova/vue-auth): vue-router.2.x.js : Vue.router must be set.

另一方面,如果我将Vue.http.options.root = 'https://api.example.com'移动到导入语句正下方,我又收到另一个错误:Uncaught TypeError: Cannot read property 'options' of undefined

+0

当我'Vue.use(VueResource)',我得到一个新的错误'错误(@ websanova/vue-auth):vue-router.2.x.js:必须设置Vue.router。' –

回答

0

您需要在您的main.js文件导入“VUE资源”得到这个错误的坐:

import Vue from 'vue' 
import VueResource from 'vue-resource'; 
import Actions from 'actions' 
import App from './App' 

Vue.use(Actions, { 
    locales: ['en', 'zh', 'fr'] 
}) 

Vue.use(VueResource) 
Vue.http.options.root = 'https://api.example.com' 

new Vue({ 
    render: h => h(App), 
    watch: { 
    lang: function (val) { 
     Vue.config.lang = val 
    } 
    } 
}).$mount('#app') 
+0

将'vue-resource'导入main.js文件会导致相同的错误:'错误(@ websanova/vue-auth):vue-resource.1.x.js:必须设置Vue.http。 –