Vuejs没有从mixins读取属性并导出NOT FOUND错误.

hid*_*dar 4 javascript webpack vue.js babeljs vuejs2

我已经处理了这个错误3天,不确定这是不是一个bug,但是我从vuejs/vue-cli安装了vuejs

使用以下说明:

npm install -g vue-cli 
vue init webpack foo.com
cd foo.com
npm install
npm run dev
Run Code Online (Sandbox Code Playgroud)

到目前为止它工作,现在我在里面创建了一个这样的目录结构 src/

— src
   — assets
   — filters
   — config
   — components
       Profiles.vue
       Login.vue
   profiles.js
   routes.js
   main.js
Run Code Online (Sandbox Code Playgroud)

所以,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
Run Code Online (Sandbox Code Playgroud)

到目前为止,我对上面的代码没有任何问题,问题来自这两个下面的文件profiles.js或者Profiles.vue

这是profiles.js

const profiles = Vue.mixin({
  data: function () {
    return { profiles: [] }
  },
  methods: {
   fetchProfiles: function(){....},
   mounted: function(){ this.fetchProfiles() }
})

export default profiles
Run Code Online (Sandbox Code Playgroud)

这是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>
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,我得到了这些错误.

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)
Run Code Online (Sandbox Code Playgroud)

如果我添加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)
Run Code Online (Sandbox Code Playgroud)

这是抱怨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'
Run Code Online (Sandbox Code Playgroud)

虽然很明显,却export default profiles没有发现抱怨profiles.js.我甚至尝试过使用require,改变路径......一切.什么都行不通.

我很感激任何帮助.

Mar*_*hia 14

profiles.js以错误的方式导入:

import { profiles } from '../../profiles'
Run Code Online (Sandbox Code Playgroud)

既然你正在使用export default它应该是

import profiles from '../../profiles'
Run Code Online (Sandbox Code Playgroud)