【发布时间】:2019-10-15 17:20:37
【问题描述】:
我正在尝试将数据从其父 .js 文件加载到我的 .vue 组件文件中。
这是我的 .html 文件:
<div class="modal-container">
<section class="modal">
<modal-component></modal-component>
</section>
</div>
这是我的 .js 文件:
var modal = new Vue({
el: 'section.modal',
data: {
msg: 'Hello world!'
},
components: {
'modal-component': httpVueLoader('./templates/test.vue')
}
});
这是我的 .vue 文件:
<template>
<section>
<p class="test">{{ msg }}</p>
</section>
</template>
但是,当我加载页面时,控制台中出现此错误,并且“msg”的值为空白:
[Vue warn]: Property or method "msg" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
【问题讨论】:
-
你要么需要在
modal-component的js文件中定义msg,要么为model-component添加一个prop并绑定msg。您的问题中缺少模型组件的 Javascript 文件。 -
缺少代码:在
</template>下添加<script> export default { data: () => { return { msg: "my message" }; } } </script>
标签: javascript vue.js vuejs2 vue-component vue-loader