瀏覽代碼

CORB issues

Jared Norris 8 年之前
父節點
當前提交
7a8f8d0432
共有 1 個文件被更改,包括 8 次插入5 次删除
  1. 8
    5
      VueApp/src/App.vue

+ 8
- 5
VueApp/src/App.vue 查看文件

@@ -1,5 +1,6 @@
1 1
 <template>
2
-  <div :style="{ backgroundImage: 'url(' + imageUrl + ')' }">
2
+  <div>  <!-- :style="{ backgroundImage: 'url(' + imageUrl + ')' }" -->
3
+    <img :src="imageUrl">
3 4
     <nav class="navbar navbar-default">
4 5
       <div class="container-fluid">
5 6
         <div class="navbar-header">
@@ -52,10 +53,12 @@ export default {
52 53
       imageUrl: ''
53 54
     }
54 55
   },
55
-  beforeMount () {
56
-    // const randomNum = (Math.random() * 19) + 1
57
-    fetch('https://thingproxy.freeboard.io/fetch/https://api.flickr.com/services/feeds/photos_public.gne?format=json&tags=mountain+road')
58
-      .then(console.log) // .then(console.log)
56
+  async beforeMount () {
57
+    const randomNum = Math.round((Math.random() * 19))
58
+    this.imageUrl = await fetch('https://thingproxy.freeboard.io/fetch/https://api.flickr.com/services/feeds/photos_public.gne?format=json&tags=mountain+road&jsoncallback=?')
59
+      .then(r => r.text())
60
+      .then(text => JSON.parse(text.substring(1, text.length - 1)))
61
+      .then(json => json.items[randomNum].link)
59 62
   },
60 63
   methods: {
61 64
     login,