Last active
April 20, 2020 15:46
-
-
Save paltman/7225dbf00202e332bf8f98c4887bf747 to your computer and use it in GitHub Desktop.
Example Vue/Django App
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
def bookmarks(request): | |
data = [b.data() for b in Bookmark.objects.all()] | |
return JSONResponse(data=dict(bookmarks=data)) |
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
<template> | |
<div class="bookmark-list"> | |
<button @click="refresh">Refresh</button> | |
<div v-for="(bookmark, index) in bookmarks" :key="index"> | |
<a :href="bookmark.url">{{ bookmark.title }}</a> | |
</div> | |
</div> | |
</template> | |
<script> | |
import api from './api'; | |
export { | |
data() { | |
return { | |
bookmarks: [], | |
} | |
}, | |
methods: { | |
refresh() { | |
api.getBookmarks(data => { | |
this.bookmarks = data.bookmarks; | |
}); | |
} | |
}, | |
created() { | |
this.refresh(); | |
} | |
} | |
</script> |
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
class Bookmark(models.Model): | |
title = models.CharField(max_length=250) | |
url = models.CharField(max_length=500) | |
def data(self): | |
return dict(title=self.title, url=self.url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment