which has only a getter"-6ren"> which has only a getter"-我正在尝试实例化一个 Vue 组件,但出现错误: [Vue warn]: Error in render: "TypeError: Cannot set property props of # whi-6ren">
gpt4 book ai didi

javascript - Vue.js : "TypeError: Cannot set property props of# which has only a getter"
转载 作者:数据小太阳 更新时间:2023-10-29 04:45:15 26 4
gpt4 key购买 nike

我正在尝试实例化一个 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>

可拖动列表.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");
}
}
};

可拖动列表组件.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;

关于javascript - Vue.js : "TypeError: Cannot set property props of#<Object> which has only a getter",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47883370/

26 4 0