【问题标题】:Is it possible to use Vue components in .vue formats vs commonJS formats interchangeably?是否可以互换使用 .vue 格式和 commonJS 格式的 Vue 组件?
【发布时间】:2017-05-15 01:41:52
【问题描述】:

这是commonJS格式

Vue.Component('custom-component',{
       template : '<p>Some template</p>',
       data : {}
       methods : {}
});

这是 .vue 格式

<template>
    <p>Some template</p>
</template>

<script>
    export default {
        data() {
           return {};
        },
        methods : {}            
    }

</script>
<style>
</style>

我的问题是,你能有一个项目,其中一些组件用 commonJS 格式编写,一些组件用 .vue 格式编写吗?如果是这样,你如何在另一种中导入一种组件?

【问题讨论】:

    标签: javascript components commonjs vue-component vue.js


    【解决方案1】:

    是的,你可以。

    .vue 文件会被打包成 common js,common js 格式会被 webpack 原样保留。

    【讨论】:

      猜你喜欢
      • 2021-08-26
      • 2021-12-31
      • 2018-05-20
      • 2018-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多