2017-12-22 89 views
1

ページが読み込まれたときにランダムなイメージを取得しようとしています。 なぜこれが動作していないのかわかりません...誰ですか?これは、バイブルとしてそれを実行しているが、私のvue-cliではなく、devサーバで動作します。Vue.jsランダムイメージimg v-bind

<template> 
    <section> 
    <img v-bind:src="selectedImage" /> 
    </section> 
</template> 

<script> 
export default { 
    data: { 
    images: [ 
     'http://via.placeholder.com/350x150', 
     'http://via.placeholder.com/200x140', 
     'http://via.placeholder.com/200x100' 
    ], 
    selectedImage: '' 
    }, 
    created() { 
    const idx = Math.floor(Math.random() * this.images.length) 
    this.selectedImage = this.images[idx] 
    } 
} 
</script> 

EDIT:コンポーネントで

import Vue from 'vue' 
import App from './App' 
import router from './router' 

Vue.config.productionTip = false 
new Vue({ 
    el: '#app', 
    router, 
    template: '<App/>', 
    components: { App } 
}) 
+0

すべきですか? –

+0

エラーメッセージは表示されませんが、イメージが表示されません。 –

+0

私は試して、それは動作します。ここをクリックしてください:https://jsfiddle.net/sb0tyuf8/ –

答えて

0

main.jsから、Dataはいつもあなたが働いていないことで、正確に何を意味する機能

関連する問題