简体   繁体   English

如何将动态变量传递给“组件”然后显示它-VueJS

[英]How to pass a dynamic variable to a 'component' and then display it - VueJS

I can not display a variable (which is the link of an image) in my component I am lost ... 我无法在我丢失的component显示变量(即图像的链接)...

(To help you, I'm in a table and click on the icon that opens a pdf) (为了帮助您,我在一张桌子上,然后单击打开pdf的图标)

Thanks you ! 谢谢 !

 Vue.component('modal', { template: '#modal-template-pdf', props: { lien: String } }); let appCompta = new Vue({ data: { showModalActive: false, currentModalPdfLink: '', } }).$mount('#'+id+' #app-compta') 
 <img slot="apercu" slot-scope="props" class="iconeged main" src="images/ico_pdf.png" v-bind:currentModalPdfLink='props.row.imglien' @click="showModalActive = true" > <modal v-if="showModalActive" @close="showModalActive = false" v-bind:lien="currentModalPdfLink"> <h3 slot="header">Aperçu PDF</h3> </modal> <script type="text/x-template" id="modal-template-pdf"> <transition name="modal"> <div class="modal-mask"> <div class="modal-wrapper"> <div class="modal-container"> <div class="modal-header"> <slot name="header"> default header </slot> </div> <div class="modal-body"> <slot name="body"> {{currentModalPdfLink}} <iframe height='100%' width='100%' frameborder='0' :src="currentModalPdfLink"/> </slot> </div> <div class="modal-footer"> <slot name="footer"> <button class="modal-default-button" @click="$emit('close')"> FERMER </button> </slot> </div> </div> </div> </div> </transition> </script> 

I assume that currentModalPdfLink is your pdf-link? 我认为currentModalPdfLink是您的pdf链接? The name of the prop that you are passing is src so you need to refer to it in your component with the same name: 您要传递的道具名称为src因此您需要在组件中使用相同的名称进行引用:

Vue.component('modal', {
    template: '#modal-template-pdf',
    props: ['src']
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM