【发布时间】:2017-10-19 21:09:01
【问题描述】:
我试图了解vue 组件的工作原理。最终目标是在我单击 Go 时向只读的 textarea 添加一行!按钮。目前我坚持使用以下代码:
// Register components
Vue.component('chatarea', {
delimiters: ['${', '}'],
props: ['msg'],
template: '<textarea readonly="" rows="20">${msg}</textarea>',
})
// Create a root instance
var app = new Vue({
el: '#app',
delimiters: ['${', '}'],
data: {
messages: [
'Hello from Vue!',
'Other line...'
],
},
methods: {
get_msg: function () {
return this.messages.reverse().join('\n');
}
}
})
以下html 以我想要的方式呈现 - 消息以相反的顺序显示:
<div class="container" id="app">
<div class="row">
<div class="col-md-8 offset-md-2">
<form action="/question" enctype="multipart/form-data" method="get" v-on:submit.prevent="onSubmit">
<div class="input-group">
<input type="text" class="form-control" placeholder="Say Something...">
<span class="input-group-btn">
<button class="btn btn-secondary" type="button">Go!</button>
</span>
</div>
</form>
</div>
</div>
<div class="row" style="">
<div class="col-md-8 offset-md-2">
<chatarea :msg="get_msg()"></chatarea>
</div>
</div>
</div>
但是我收到以下警告:
[Vue 警告]:组件渲染函数中可能存在无限更新循环。
我知道我做错了什么...这里是JSFiddle
【问题讨论】:
标签: javascript vuejs2