詳解auto-vue-file:一個(gè)自動(dòng)創(chuàng)建vue組件的包
auto-vue-file
auto create .vue file by shell command
通過(guò)終端自動(dòng)創(chuàng)建vue文件
前言:
1: 我們?cè)趯?xiě)xxx.vue頁(yè)面文件的時(shí)候,一般都要寫(xiě)這些重復(fù)的代碼:
<template> <div class="zlj-comp-ct"> zlj組件 </div> </template> <script> export default { name: 'zlj' } </script> <style lang="scss" scoped> .zlj-comp-ct { } </style>
2:寫(xiě)組件的時(shí)候可能還要在components目錄下面新建一個(gè)目錄: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
每次都寫(xiě)這些代碼,是不是很煩?
主角登場(chǎng):auto-vue-file
安裝
npm install auto-vue-file -g
使用
auto-vue-file -c
結(jié)果
這樣在components目錄下面生成myForm文件
參數(shù)說(shuō)明:
名稱(chēng) | 說(shuō)明 | 使用例子 |
---|---|---|
component | 創(chuàng)建一個(gè)vue組件, 默認(rèn)在components目錄下面 | auto-vue-file -c 或 auto-vue-file --component |
page | 創(chuàng)建一個(gè)vue組件,默認(rèn)在views目錄 | auto-vue-file -p 或 auto-vue-file --page |
path | 在指定目錄創(chuàng)建vue組件,需要提供-c或-p參數(shù) | auto-vue-file -c --path ./src/haha 或 auto-vue-file -p --path ./src/haha |
更多:
你也可以使用自己的vue模版文件,文件名為auto-vue-file.template.js,存放在項(xiàng)目根目錄下面,內(nèi)容如下
// 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}`} }
你也可以執(zhí)行
auto-vue-file --init
自動(dòng)生成該配置文件:auto-vue-file.template.js
然后改成你自己需要的樣子。
總結(jié)
以上所述是小編給大家介紹的uto-vue-file:一個(gè)自動(dòng)創(chuàng)建vue組件的包,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
相關(guān)文章
如何使用Nginx將前端Vue項(xiàng)目部署到云服務(wù)器
記錄使用Nginx將純前端的Vue3項(xiàng)目部署到阿里云服務(wù)器(Ubuntu?22.04)上,包含通過(guò)Nginx代理實(shí)現(xiàn)跨域請(qǐng)求、以及個(gè)人踩坑記錄,感興趣的朋友一起看看吧2024-04-04Vue關(guān)于Element UI中的文本域換行問(wèn)題
這篇文章主要介紹了Vue關(guān)于Element UI中的文本域換行問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03超詳細(xì)教程實(shí)現(xiàn)Vue底部導(dǎo)航欄TabBar
本文詳細(xì)講解了Vue實(shí)現(xiàn)TabBar底部導(dǎo)航欄的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-11-11vue+element-plus上傳圖片及回顯問(wèn)題及數(shù)量限制
本文主要介紹了vue+element-plus上傳圖片及回顯問(wèn)題及數(shù)量限制,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04詳解vue父子組件關(guān)于模態(tài)框狀態(tài)的綁定方案
這篇文章主要介紹了詳解vue父子組件關(guān)于模態(tài)框狀態(tài)的綁定方案,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-06-06