【问题标题】:How to pass custom nativescript-Vue component to custom child Component如何将自定义 nativescript-Vue 组件传递给自定义子组件
【发布时间】:2018-07-24 13:04:25
【问题描述】:

我想使用 Nativescript-Vue 将动态子组件添加到父组件。例如:

<template>
    <MyParentComponent>
        <MyChildComponent :foo="foo"></MyChildComponent>
    </MyParentComponent>
<template>

<script>
    import MyParentComponent from './components/MyParentComponent';
    import MyChildComponent from './components/MyChildComponent';

    export default {
        components: {
            MyParentComponent,
            MyChildComponent
        },
        data: function(){
            return {
                foo: ''
            }
        }
    }
</script>

我想我需要在父组件中定义一个应该插入子组件的插槽,但我不知道该怎么做。

有什么想法吗?

【问题讨论】:

    标签: nativescript nativescript-vue


    【解决方案1】:

    MyParentComponent的模板中,你需要添加一个&lt;slot /&gt;标签,这是Vue插入内容的地方。

    在 Vue 文档中阅读更多关于插槽以及它们可以做什么的信息: https://vuejs.org/v2/guide/components.html#Content-Distribution-with-Slots

    【讨论】:

    • 太棒了。所以它和 Vue.js 中的完全一样。我不知道为什么我的测试之前失败了,但现在它完美无缺。谢谢!
    猜你喜欢
    • 2020-06-04
    • 1970-01-01
    • 2020-04-18
    • 2018-09-16
    • 2021-12-28
    • 1970-01-01
    • 2011-11-12
    • 2017-07-06
    • 1970-01-01
    相关资源
    最近更新 更多