如何在 html 参数中添加插槽?



在我的 Vue.js 组件中,我需要在参数中使用 slot,但我的尝试不起作用。有没有办法做到这一点?


new Vue({
el: '#app',
components: {
'test': {
template: `
<iframe width="300px" height="200px" src="https://www.youtube.com/embed/<slot></slot>"></iframe>
`
}
}
})

插槽用于插入你需要的 html 道具 试试这个它会起作用

components: {
test:{
template:'<iframe width="300px" height="200px" :src="url"></iframe>',
props: ['url'],
}
}

并传递来自父级的网址

<test url="https://www.youtube.com/embed/-rCZNFARSfQ" />

最新更新