vue.js - 无法使用Typescript在vuejs中导入多个组件

标签 vue.js vuejs2 vue-component

我有两个组件,我想在其他组件上使用它们,如下所示

import { Component, Vue } from 'vue-property-decorator'
import DDGDriver from '@/components/ddg-driver.vue'
import OverLay from '@/components/overlay.vue'

@Component({
  components: {
    'over-Lay':OverLay,  'DDGDriver':DDGDriver
  }
})
export default class DDGPage extends Vue {
  showModal = true;
  onModalClose(){
    this.showModal = false;
  }
}

但它不起作用,只有第二个导入组件被放置而不是第一个,我不知道为什么会这样。

<template>
  <div>
     <over-Lay v-on:close="onModalClose()" v-if="showModal">
        <DDGDriver /> 
     </over-Lay>
  </div>
</template>

DDG驱动组件

<template>
    <div class="driver">
        <h1>this is ddg driver</h1>
    </div>
</template>

<script>
import Vue from 'vue';

export default class DDGDriver extends Vue   {
}
</script>

<style lang="less" scoped>
.driver{
    height:auto;
    width: 400px;
    background-color: #FFF;
}
</style>

OverLay 组件

<template>
    <div class="overlay">
        <div class="containt">
            <div @click="removeModal()" class="close">X</div>
             <slot>
    This will only be displayed if there is no content
    to be display.
  </slot>
        </div>
    </div>
</template>

<script>
import Vue from "vue";

export default class OverLay extends Vue {
  removeModal(){
    this.$emit('close');
  }
}
</script>

<style lang="less" scoped>
.overlay {
  position: fixed;
  bottom: 0px;
  right: 0px;
  left: 0px;
  top: 0px;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  .containt {
    min-width: 20px;
    height: auto;
    background-color: #fff;
    padding: 15px;
    .close {
      position: relative;
      top: -32px;
      right: -27px;
      float: right;
      height: 25px;
      width: 25px;
      background: #fff;
      border-radius: 50%;
    }
  }
}
</style>

最佳答案

您忘记在子组件中添加 @Component({})

<script>
  import Vue from 'vue';
  @Component({})
  export default class DDGDriver extends Vue {}
</script>

关于vue.js - 无法使用Typescript在vuejs中导入多个组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53933126/

相关文章:

javascript - Vue Js如何在单文件模板中使用mixins?

vue.js - Vue.js react 性如何在幕后工作?

javascript - 如何在 vue js html 中使用数组检查 v-if 条件?

vue.js - 如何在 VueJs 中将 child 渲染到指定的命名插槽中?

javascript - 使用 Vue 动态加载时 HTML 数据列表不断崩溃

javascript - Vuejs 在组件之间共享数据

vuejs2 - 如何改进 axios.spread

javascript - 导入 Vue 组件

unit-testing - 自 ag-grid 集成以来 Jest vuejs 崩溃

vue.js - 数组内对象的 VueJS react 性问题