代码之家  ›  专栏  ›  技术社区  ›  hidar

Vuejs未从混合和导出中读取属性未找到错误。

  •  5
  • hidar  · 技术社区  · 7 年前

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

    使用以下说明:

    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

    这是 配置文件。js公司

    const profiles = Vue.mixin({
      data: function () {
        return { profiles: [] }
      },
      methods: {
       fetchProfiles: function(){....},
       mounted: function(){ this.fetchProfiles() }
    })
    
    export default 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' 将上述错误替换为以下错误:

    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], 在里面 配置文件。js公司 profiles prop未定义,但事实并非如此。出于某种原因 配置文件。vue 未从中读取或读取正确的数据 因为我总是会遇到这样的错误:

    [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 尽管它确实如此。我甚至尝试使用require,更改路径。。。每件事什么都不管用。

    1 回复  |  直到 7 年前
        1
  •  17
  •   Mario Lamacchia    7 年前

    您正在导入 profiles.js

    import { profiles } from '../../profiles'
    

    export default ,应该是

    import profiles from '../../profiles'