动态图像绑定vue

2022-01-25 00:00:00 vue.js vue-component vuejs2

我想和这里一样,但我想使用 images.sample 作为参数,例如 props:['images.sample'],

I want to do the same as here but instead I want to use images.sample as parameter e.g props:['images.sample'],

<template>
<img :src="images.sample">
</template>

<script>
export default {
    data() {
        return {
            images: {
                sample: require('./assets/static/images/sample.jpg')
            }
        }
    }
}
</script>

推荐答案

你的子组件应该是这样的:

Your child component should be like :

<template>
<img :src="url">
</template>

<script>
export default {
  name:'child-img',
   props:['url'],
    data() {
        return {

        }
    }
}
</script>

父组件应该有这个内容:

the parent component should have this content :

<template>
<child-img :url="images.sample"/>
</template>

<script>
export default {
    data() {
        return {
            images: {
                sample: require('./assets/static/images/sample.jpg')
            }
        }
    }
}
</script>

相关文章