Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 2相同的文件,如何在Vue.js 2中构建模板/组件2_Templates_Vue.js_Vuejs2_Vue Component - Fatal编程技术网

Templates 2相同的文件,如何在Vue.js 2中构建模板/组件2

Templates 2相同的文件,如何在Vue.js 2中构建模板/组件2,templates,vue.js,vuejs2,vue-component,Templates,Vue.js,Vuejs2,Vue Component,我使用的是Vue.js 2.0,我在两个不同的文件中使用了完全相同的代码,唯一改变的是这个块的ID_-SPECIFIC_,所以我是Vue的初学者,我想知道是否有一种方法可以实现一种模板,可以在我的两个文件中重复使用 您可以在下面找到一个文件的完整代码: <template> <div> <div class="container"> <hp-row> <hp-co

我使用的是Vue.js 2.0,我在两个不同的文件中使用了完全相同的代码,唯一改变的是这个块的ID_-SPECIFIC_,所以我是Vue的初学者,我想知道是否有一种方法可以实现一种模板,可以在我的两个文件中重复使用

您可以在下面找到一个文件的完整代码:

<template>
    <div>
        <div class="container">
            <hp-row>
                <hp-column>
                    <component v-for="component in content.column" :data="component" :key="component.id" :is="getComponentIdentifier(component.is)"></component>
                </hp-column>
            </hp-row>
        </div>
    </div>
</template>

<script>
import ModularView from '@/views/ModularView'

export default {
    name: 'AboutUsView',
    mixins: [ModularView],

    created () {
        this.fetch('blocks/ID_SPECIFIC_TO_THIS_BLOCK')
    },
}
</script>

从“@/views/ModularView”导入ModularView
导出默认值{
名称:“AboutUsView”,
mixins:[模块视图],
创建(){
this.fetch('blocks/ID\u SPECIFIC\u TO\u this\u BLOCK')
},
}
使用道具:

export default {
    name: 'AboutUsView',
    mixins: [ModularView],
    props: ['ID_SPECIFIC_TO_THIS_BLOCK']
    created () {
        this.fetch(`blocks/${this.ID_SPECIFIC_TO_THIS_BLOCK}`)
    },
}

<about-us-view ID_SPECIFIC_TO_THIS_BLOCK="123"></about-us-view>
<about-us-view ID_SPECIFIC_TO_THIS_BLOCK="789"></about-us-view>
导出默认值{
名称:“AboutUsView”,
mixins:[模块视图],
道具:['ID_SPECIFIC_TO_THIS_BLOCK']
创建(){
this.fetch(`blocks/${this.ID\u SPECIFIC\u TO\u this\u BLOCK}`)
},
}

首先感谢您的回答,很抱歉,我不明白,为什么要在脚本中使用HTML?我在脚本中没有使用HTML,只是展示了当您使用该组件时如何传递道具。很抱歉,我是初学者,您在回答中没有使用任何进一步的解释或来源,因此您可能做得对,但我不理解it@Ced请参阅并特别注意“使用道具将数据传递给子组件”部分。我可以提供一个工作示例吗?我试过了,但没有效果,@Bhojendra Rauniyar的代码对我来说不清楚