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"; "use strict";
$(function(){ $(function(){
// At tutorial chapter1, sending request to fluentd
if($('#chapter1').length === 0) return; if($('#chapter1').length === 0) return;
new Vue({ new Vue({
el: "#chapter1", el: "#chapter1",
data: { data: {
"logs": [],
"payloads": [ "payloads": [
{ {
"path": "/debug.foo", "path": "/debug.foo",
@ -37,19 +38,7 @@
] ]
}, },
created: function(){
this.fetchLogs();
},
methods: { 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){ sendRequest: function(payload){
new Promise(function(resolve, reject) { new Promise(function(resolve, reject) {
$.ajax({ $.ajax({

View File

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