Separate vue components

This commit is contained in:
uu59 2014-06-09 16:34:00 +09:00
parent 5d32e167a8
commit 15d3d3248f
3 changed files with 36 additions and 13 deletions

View File

@ -0,0 +1,30 @@
(function(){
"use strict";
$(function(){
if($('#fluent-log').length === 0) return;
new Vue({
el: "#fluent-log",
data: {
"logs": [],
},
created: function(){
this.fetchLogs();
},
methods: {
fetchLogs: function() {
var self = this;
new Promise(function(resolve, reject) {
$.getJSON("/tutorials/log_tail", resolve).fail(reject);
}).then(function(logs){
self.logs = logs;
});
},
}
});
});
})();

View File

@ -2,12 +2,13 @@
"use strict";
$(function(){
// At tutorial chapter1, sending request to fluentd
if($('#chapter1').length === 0) return;
new Vue({
el: "#chapter1",
data: {
"logs": [],
"payloads": [
{
"path": "/debug.foo",
@ -37,19 +38,7 @@
]
},
created: function(){
this.fetchLogs();
},
methods: {
fetchLogs: function() {
var self = this;
new Promise(function(resolve, reject) {
$.getJSON("/tutorials/log_tail", resolve).fail(reject);
}).then(function(logs){
self.logs = logs;
});
},
sendRequest: function(payload){
new Promise(function(resolve, reject) {
$.ajax({

View File

@ -20,7 +20,11 @@
</code>
</p>
</form>
</div>
<!-- /vue.js -->
<!-- vue.js -->
<div id="fluent-log">
<pre>
<button class="btn btn-primary" v-on="click: fetchLogs"><%= t ".reload_log" %></button>