当前位置: 移动技术网 > IT编程>脚本编程>vue.js > 详解auto-vue-file:一个自动创建vue组件的包

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

2019年07月21日  | 移动技术网IT编程  | 我要评论

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

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

总结

以上所述是小编给大家介绍的uto-vue-file:一个自动创建vue组件的包,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网