auto-vue-file:一个自动创建vue组件的包

介绍了一种通过终端命令自动创建标准Vue组件和页面的方法,利用auto-vue-file工具简化开发流程,减少重复工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

auto-vue-file

auto create .vue file by shell command 通过终端自动创建vue文件

前言:

1: 我们在写xxx.vue页面文件的时候,一般都要写这些重复的代码:

<template>
  <div class="zlj-comp-ct">
    zlj组件
  </div>
</template>
<script>
export default {
  name: 'zlj'
}
</script>
<style lang="scss" scoped>
.zlj-comp-ct {

}
</style>

复制代码

2:写组件的时候可能还要在components目录下面新建一个目录:xxx,里面是xxx.vue和index.js

比如myForm组件

// myForm.vue
<template>
  <div class="myForm-comp-ct">
    myForm组件
  </div>
</template>
<script>
export default {
  name: 'myForm'
}
</script>
<style lang="scss" scoped>
.myForm-comp-ct {

}
</style>
// index.js
import myForm from './myForm.vue'
export default myForm

复制代码

每次都写这些代码,是不是很烦?

主角登场:auto-vue-file
安装
npm install auto-vue-file -g
复制代码
使用
 auto-vue-file -c
复制代码
结果

这样在components目录下面生成myForm文件

参数说明:
名称说明使用例子
component创建一个vue组件, 默认在components目录下面auto-vue-file -c 或 auto-vue-file --component
page创建一个vue组件,默认在views目录auto-vue-file -p 或 auto-vue-file --page
path在指定目录创建vue组件,需要提供-c或-p参数auto-vue-file -c --path ./src/haha 或 auto-vue-file -p --path ./src/haha
更多:

你也可以使用自己的vue模版文件,文件名为auto-vue-file.template.js,存放在项目根目录下面,内容如下

// template.js you can generate
//  auto-vue-file.template.js
        module.exports = {
          vueTemplate: componentName => {
            return `<template>
          <div class="${componentName}-comp-ct">
            ${componentName}组件
          </div>
        </template>
        <script>
        export default {
          name: '${componentName}'
        }
        </script>
        <style lang="scss" scoped>
        .${componentName}-comp-ct {
        
        }
        </style>
        `
          },
         entryTemplate:  componentName => {
            return `import ${componentName} from './${componentName}.vue'
        export default ${componentName}`}
        }

复制代码

你也可以执行

auto-vue-file --init
复制代码

自动生成该配置文件:auto-vue-file.template.js

然后改成你自己需要的样子。

最后:

参考:juejin.im/post/5c4a6f…

github

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值