我试图实例化Vue组件,但出现错误:

[Vue warn]: Error in render: "TypeError: Cannot set property props of
#<Object> which has only a getter"
(found in <Root>)

我也在使用vuedraggable库,但我认为问题更多是Vue问题而不是vuedraggable问题。下面是我的代码。

这是draggable-list.vue
<template src="./draggable-list-component.html"></template>
<script src="./draggable-list.js"></script>

draggable-list.js
const draggable = require("vuedraggable");

module.exports = {
  name: "draggable-list",
  components: {
    draggable
  },

  // properties which has been passed from the parent vue to the component
  props: ["title", "elements"],

  data() {
    return {
      isDragging: false,
    };
  },

  methods: {
    test() {
      console.log("blou");
    }
  }
};

draggable-list-component.html:
<div id="draggable-list">
  <draggable element="ul"
             :list="elements">
    <!-- TODO -->
  </draggable>
</div>

我的main.js然后调用另一个js文件:
require("./components/manager");

在经理中,我实例化了Vue实例:
const Vue = require("vue/dist/vue.common");
const draggableList = require("./draggable-list.vue");

let triggerLibrary;

triggerLibrary = new Vue({
  el: "#draggable-list",
  template: "<draggableList :title='title' :elements='triggerElements'
/>",
  components: {draggableList},

  data: {
   title: "Trigger library",
    triggerElements: [{name:"Trigger name", description:"Quick trigger
description"}]
  }
});

我在index.html中像这样使用它:
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>planner</title>
  </head>
  <body>
  <div id="draggable-list">
    <draggable-list></draggable-list>
  </div>
  </body>

有人看到这里有什么问题吗?

最佳答案

在使用CommonJS模块时,请尝试以这种方式要求Vue组件:

const draggableList = require("./draggable-list.vue").default;

09-25 19:57