Created
February 25, 2020 07:51
-
-
Save h2ospace/663d2a1ceee01960851fdb034eb0fc30 to your computer and use it in GitHub Desktop.
Ajax by Vue.js with axios
This file contains 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
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<div id="news"> | |
<ul> | |
<li v-for="item in items">{{ item.title }}</li> | |
</ul> | |
</div> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> | |
<script> | |
var app = new Vue({ | |
el: '#news', | |
data: { | |
items: {} | |
}, | |
mounted: function () { | |
var self = this; | |
axios.get('feed.json').then(function(res) { | |
self.items = res.data.items; | |
}); | |
// $.getJSON('feed.json', function (json) { | |
// self.items = json.items; | |
// }); | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment