Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.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
Javascript 如何将主要组件直接导入到*.vue文件,而不是导入到vue中的主*.js文件?_Javascript_Vue.js_Vuejs2_Vue Component_Vue Router - Fatal编程技术网

Javascript 如何将主要组件直接导入到*.vue文件,而不是导入到vue中的主*.js文件?

Javascript 如何将主要组件直接导入到*.vue文件,而不是导入到vue中的主*.js文件?,javascript,vue.js,vuejs2,vue-component,vue-router,Javascript,Vue.js,Vuejs2,Vue Component,Vue Router,我的apiCall.vue文件如下所示,我想在这里直接添加prime组件,而不是从index.js文件加载它。我想从js文件中删除该组件,并想直接使用到vue文件中。可能吗 <template> <DataTable :value="cars"> <Column field="vin" header="Vin"></Column> <Column field="year" header="Year"></Colu

我的apiCall.vue文件如下所示,我想在这里直接添加prime组件,而不是从index.js文件加载它。我想从js文件中删除该组件,并想直接使用到vue文件中。可能吗

 <template>
<DataTable :value="cars">
    <Column field="vin" header="Vin"></Column>
    <Column field="year" header="Year"></Column>
</DataTable>
</template>

<script>

export default {
  name: 'ApiCall',
  data() {
        return {
            columns: null,
            cars: null
        }
  },
  mounted() {
         this.columns = [
            {field: 'vin', header: 'Vin'},
            {field: 'year', header: 'Year'},
            {field: 'brand', header: 'Brand'},
            {field: 'color', header: 'Color'}
        ];
        this.cars =[
        {vin:'dsad231ff',year:'2012',brand:'Volkswagen',color:'Orange'},
        {vin:'dsad231ff',year:'2012',brand:'Volkswagen',color:'Orange'},
        {vin:'dsad231ff',year:'2012',brand:'Volkswagen',color:'Orange'},
        {vin:'j6w54qgh',year:'2009',brand:'BMW',color:'Blue'}
        ];
     }
}
</script>

<style>
</style>

我是Vue新手。

您可以在.Vue文件脚本部分中导入组件:

<script>
import DataTable from 'primevue/datatable';
import Column from 'primevue/column';
export default {
...
  components: {
    DataTable,
    Column
  }
}
</script>

从“primevue/DataTable”导入数据表;
从“primevue/列”导入列;
导出默认值{
...
组成部分:{
数据表,
纵队
}
}

hi,这是我第一次尝试时使用的,但当我将它与VueMaterial一起使用时,它不起作用,有什么建议吗?根据下面的链接,vue material npm不可能使用它,因此最好不要使用它来提高性能。改用primevue。
<script>
import DataTable from 'primevue/datatable';
import Column from 'primevue/column';
export default {
...
  components: {
    DataTable,
    Column
  }
}
</script>