繁体   English   中英

从Laravel视图将属性传递到Treeselect Vue组件

[英]Pass in an attribute into Treeselect vue component from Laravel view

我正在尝试包装Vue-Treeselect链接: https ://vue-treeselect.js.org/#node在它自己的vue组件中,因此我可以在Laravel视图文件中简单地包含例如<tree-select></tree-select>我需要的地方。

我不知道的是,如何从Laravel视图传递一些实例特定的道具并使用组件模板中的属性值? 我想从Laravel视图中传递字段名称,如下所示: <tree-select name='property_ids'></tree-select>稍后,vue组件模板可以使用传入的名称作为组件内部的name属性模板。

我正在使用https://vue-treeselect.js.org/中的入门代码,因此在我的Laravel视图表单中,我想要这个标签
<tree-select name='property_ids'></tree-select>但是,如何在vue组件模板(下面的示例代码)内部设置name属性值?

<template>
    <div>
        <treeselect v-model="value" :multiple="true" :options="options" name="passedInName"></treeselect>
    </div>
</template>

<script>
    // import the component
    import Treeselect from '@riophae/vue-treeselect'
    // import the styles
    import '@riophae/vue-treeselect/dist/vue-treeselect.css'

    export default {
        // register the component
        components: { Treeselect },
        data() {
            return {
                // define the default value
                value: [],
                // define options
                options: [  {
                    id: 'b',
                    label: 'b',
                }, {
                    id: 'z',
                    label: 'z',
                }, {
                    id: 'x',
                    label: 'x',
                } , {
                    id: 'v',
                    label: 'v',
                }],
            }
        },
    }
</script>

您必须在vue组件中声明传递的props才能在模板中使用它们

<template>
    <div>
        <!-- Pass the prop to the name attribute -->
        <treeselect v-model="value" :multiple="true" :options="options" :name="this.name">
        </treeselect>
    </div>
</template>

<script>
export default {
    props: ['name'], // <-- The declared prop
};
</script>

暂无
暂无

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

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