【发布时间】:2017-12-11 07:56:57
【问题描述】:
我创建了一个视觉辅助工具来帮助解释我的想法(请忽略拼写错误):
我的想法是,您可以从列表中选择一个收件人,并使用所选收件人的信息更新另一个组件。现在我尝试了这个,但我一直遇到特定错误Uncaught TypeError: Right-hand side of 'instanceof' is not an object。
所以现在我认为这是不可能的?
更新:
Vue.component('ChatRecipientList', {
template: 'Set the recipient to "Jamie"',
name: 'list-component',
props: {
recipient: null
},
mounted() {
recipient = 'Jamie';
}
})
Vue.component('MessagesView', {
template: 'Showing messages for <span>{{ recipient }}</span>',
name: 'show-messages-component',
props: {
recipient: null
}
})
Vue.component('ChatContainer', {
template: '<h1>Chat</h1>' +
'<list-component :recipient.sync="this.recipient" />' +
'<show-messages-component :recipient.sync="this.recipient" />',
name: 'chat-container',
data() {
return { recipient: null }
}
})
var app = new Vue({
el: '#app'
});
<script src="https://cdn.jsdelivr.net/vue/1.0.16/vue.js"></script>
<div id="app">
<chat-container/>
</div>
谢谢, 杰米
【问题讨论】:
-
完全可以做到,能否提供一个 JSFiddle 供我们使用?基本上,您的
Messages view组件将有一个简单的道具并将其显示出来,而您的Chat Recipient List将在修改时发送一个事件,因此父组件将能够更新该值。 -
只有图像对我们没有意义。始终在问题本身中提供代码/code-sn-p
-
我已经用 JSFiddle 编辑了我的帖子,尽管遇到了问题。我从来没有在 VueJS 中使用过 JSFiddle
标签: javascript vuejs2