Forked from ITSecMedia/gist:f008f2ccb692277dfc12e6853e8da6fb
Created
August 21, 2018 21:01
-
-
Save kaliatech/ef02fa0b2021678333729bf4994fd0f8 to your computer and use it in GitHub Desktop.
simple vue.js 2.0 example to add dynamic values in gohugo.io static websites.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=== rest.php === | |
some php that creates html output | |
=== put in your app.js === | |
$( document ).ready(function() { | |
var url_api = 'http://www.domain.com/api/rest.php'; | |
var header = new Vue({ | |
delimiters: ['((', '))'], | |
el: '#api', | |
data: { | |
message: '...' | |
}, | |
created: function () { | |
this.fetchData(); | |
}, | |
methods: { | |
fetchData: function () { | |
var self = this; | |
$.get( url_api, function( data ) { | |
self.message = data; | |
// console.log(data); | |
}); | |
} | |
} | |
}) | |
}); | |
=== inside your hugo layout === | |
<script type="text/javascript" src="{{ "js/vue.min.js" | absURL }}"></script> | |
<div id="api"> | |
<div v-html="message"></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment