it-source

Vuejs가 mixin에서 속성을 읽지 않음 및 내보내기 NOT FOUND 오류입니다.

criticalcode 2022. 11. 19. 11:31
반응형

Vuejs가 mixin에서 속성을 읽지 않음 및 내보내기 NOT FOUND 오류입니다.

이 에러는 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

여기 프로파일이 있습니다.표시하다

<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,나는 생각하고 있다.profilesprop는 정의되어 있지 않지만 그렇지 않습니다.웬일인지 그래.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를 사용하여 경로 변경도 시도했습니다.전부다.아무것도 안 돼.

이 건에 대해 어떤 도움이라도 주시면 감사하겠습니다.

Import 중profiles.js잘못된 방법으로:

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

사용하고 계시기 때문에export default,그럴 것 같네요.

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

언급URL : https://stackoverflow.com/questions/45878277/vuejs-not-reading-property-from-mixins-and-export-not-found-error

반응형