我已经犯了这个错误3天了,不确定这是不是一个错误,但是我从vuejs/vue-cli安装了vuejs
使用以下说明:
npm install -g vue-cli
vue init webpack foo.com
cd foo.com
npm install
npm run dev
到目前为止它的工作原理,现在我在src/
— src
— assets
— filters
— config
— components
Profiles.vue
Login.vue
profiles.js
routes.js
main.js
所以,在routes.js
我有类似的东西。
// routes.js
import ProfilesView from './components/Profiles.vue'
import LoginView from './components/Login.vue'
const routes = [{
path: '/profiles',
component: ProfilesView
},
{
path: '/login',
component: LogoutView
}]
export default routes
到目前为止,我对上述代码没有任何问题,问题来自以下两个文件profiles.js
或Profiles.vue
这是 profiles.js
const profiles = Vue.mixin({
data: function () {
return { profiles: [] }
},
methods: {
fetchProfiles: function(){....},
mounted: function(){ this.fetchProfiles() }
})
export default profiles
这是 Profiles.vue
<template lang="html">
<div> {{ profiles }}<div>
</template>
<script>
import { profiles } from '../../profiles'
export default {
mixins: [profiles],
data () {
return { profiles: [] }
},
mounted () {}
}
</script>
<style lang="css">
</style>
使用上面的代码,我得到了这些错误。
profiles.js:1 Uncaught ReferenceError: Vue is not defined
at Object.<anonymous> (profiles.js:1)
at __webpack_require__ (bootstrap 1995fd0fa58cb1432d6f:659)
at fn (bootstrap 1995fd0fa58cb1432d6f:85)
at Object.defineProperty.value (app.js:55806)
at __webpack_require__ (bootstrap 1995fd0fa58cb1432d6f:659)
at fn (bootstrap 1995fd0fa58cb1432d6f:85)
at Object.<anonymous> (Profiles.vue:7)
at __webpack_require__ (bootstrap 1995fd0fa58cb1432d6f:659)
at fn (bootstrap 1995fd0fa58cb1432d6f:85)
at Object.__webpack_exports__.a (app.js:56033)
如果我将import Vue from 'vue'
添加到profiles.js
,则会将上述错误替换为此错误:
Uncaught TypeError: Cannot read property 'components' of undefined
at checkComponents (vue.esm.js:1282)
at mergeOptions (vue.esm.js:1363)
at mergeOptions (vue.esm.js:1379)
at Function.Vue.extend (vue.esm.js:4401)
at Object.exports.createRecord (index.js:47)
at Profiles.vue:26
at Object.<anonymous> (Profiles.vue:30)
at __webpack_require__ (bootstrap 625917526b6fc2d04149:659)
at fn (bootstrap 625917526b6fc2d04149:85)
at Object.__webpack_exports__.a (app.js:56036)
这是抱怨mixins: [profiles],
中的profiles.js
,我认为profiles
道具未定义,但事实并非如此。出于某种原因,Profiles.vue
没有从profiles.js
读取或读取正确的数据,因为我也总是收到此错误:
[HMR] bundle has 1 warnings
client.js:161 ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?type=script&index=0!./src/components/Profiles.vue
6:11-15 "export 'profiles' was not found in '../../profiles'
在export default profiles
中找不到抱怨profiles.js
,即使它显然也是如此。我甚至尝试过使用require,改变路径......一切。什么都行不通。
我将不胜感激任何帮助。
答案 0 :(得分:7)
您正以错误的方式导入profiles.js
:
import { profiles } from '../../profiles'
由于您使用的是export default
,因此应该
import profiles from '../../profiles'