简体   繁体   English

为什么我不能再次将组件导入到 VUE 中?

[英]Why can't I import a component into VUE a second time?

this is the structure of my project这是我项目的结构

src
  components
         create.vue
         resume.vue
         service.vue
  shared
         header.vue
         menu.vue
         loader.vue
         footer.vue

this is my loader component这是我的加载程序组件

<template>
    <div class="three col">
        <!-- <div class="loader" id="spinner"></div> -->
        <div class="loader" id="spinner-2">
          <span></span>
          <span></span>
          <span></span>
        </div>
    </div>
</template>

<script>
export default {
  name: 'Loader',
    
}
</script>

and I have it imported and running on my component create.vue我将它导入并在我的组件 create.vue 上运行

<template>
              <div v-show="formInfo.selectedId != ''">
                <h1 class="title">What's the name of your
                  <span>{{idName}}</span> ?
                </h1>
                <input
                type="text"
                class="form-control"
                v-model="formInfo.name"
                @keypress="onChangeName($event)"
                @keyup="onChangeName($event)"
                />
                <div class="loader-spinner" v-if="loading">
                  <ciev-app-loader>
                </div>
              </div>

</template>
<script>
import Loader from '../shared/loader.vue'

export default {
  data() {
    return {
      step: 1,
      specieName: "",
      breedName: "",
      animalName: "",
      breedId: 0,
      imageSelected: false,
      isFormCompleted: false,
      isBreedSelected: false,
      loading: false,
      isLoaderFinished: false,
      myTimeout: 0
    };
  },
  components: {
    'ciev-app-loader': Loader
  },


up to this point everything works fine, but now I want to reuse the component Loader in my component resume.vue.到目前为止一切正常,但现在我想在我的组件 resume.vue 中重用组件加载器。 I import it and declare it in the template as follows我导入它并在模板中声明它如下

<template>
      <div
        v-show="!displayUnknown"
        class="column"
        v-bind:class="{ paymentIsActive: 'payment' === selectedResume }"
        @click="onClickResume('payment')"
      >
        <label>
          <input
            type="radio"
            name="selectedResume"
            value="payment"
            v-model="selectedResume"
          />
          <i class="icon-card"></i>
        </label>
      </div>

    <div class="loader-spinner">
      <ciev-app-loader />
    </div>




</template>

<script>
import globalAxios from "axios";
import { isMobile } from "mobile-device-detect";
import Config from "./../../config.js";
import FileSaver from 'file-saver';
import { saveAs } from 'file-saver';
import Loader from '../shared/loader.vue'

export default {
  data() {
    return {
      step: 3,
      selectedResume: "",
      selectedCremationService: null,
      focusService: undefined,
      selectedServicePrice: 0.0,
      displayResume: false,
      displayUnknown: false,
      offer: "unknown",
      isMobile: isMobile ? true : false,
    };
  },
  components: {
    'ciev-app-loader': Loader
  },
</script>

The Loader component is not shown in the template, although inspecting elements in the browser does load it, and it returns me by console the following error "[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option." Loader 组件未显示在模板中,尽管在浏览器中检查元素确实加载了它,并且它通过控制台向我返回以下错误“[Vue 警告]:未知的自定义元素:-您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。”

Looking at references to the same error, I have declared the name on the component porpio when exporting it, but I think I have already done it in the Loader.查看对相同错误的引用,我在导出时在组件porpio上声明了名称,但我认为我已经在Loader中完成了。 What am I doing wrong?我究竟做错了什么?

Thank you all for your time and help in advance.提前感谢大家的时间和帮助。

The root <div> seems to have closed incorrectly in the resume.vue component.<div>似乎在resume.vue组件中错误关闭。 Correct it and try again.更正它并重试。


 <div
        v-show="!displayUnknown"
        class="column"
        v-bind:class="{ paymentIsActive: 'payment' === selectedResume }"
        @click="onClickResume('payment')"
      >
        <label>
          <input
            type="radio"
            name="selectedResume"
            value="payment"
            v-model="selectedResume"
          />
          <i class="icon-card"></i>
        </label>

    <div class="loader-spinner">
      <ciev-app-loader />
    </div>
</div>

checking my code carefully the error was that besides declaring in the script the components object with the declaration of the imported component I had declared it in duplicate at the end of the script as an empty object and this generated the error.仔细检查我的代码,错误是除了在脚本中声明组件对象和导入组件的声明外,我在脚本末尾将其重复声明为空对象,这产生了错误。 thanks for your help感谢您的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM